openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1038004 [2/2] - in /openjpa/sandboxes/jest/openjpa-persistence/src/main: java/org/apache/openjpa/persistence/jest/ resources/org/apache/openjpa/persistence/jest/
Date Tue, 23 Nov 2010 07:27:25 GMT
Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesFormatter.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesFormatter.java?rev=1038004&r1=1038003&r2=1038004&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesFormatter.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesFormatter.java
Tue Nov 23 07:27:24 2010
@@ -22,44 +22,37 @@ package org.apache.openjpa.persistence.j
 import java.util.Arrays;
 import java.util.Map;
 
+import org.apache.openjpa.persistence.jest.HTMLElement.Tag;
+import static org.apache.openjpa.persistence.jest.Constants.*;
+
 /**
- * Formats a key-value pair in a HTML table.
+ * Formats a key-value pair in a HTML Document.
  * 
  * @author Pinaki Poddar
  *
  */
 class PropertiesFormatter {
-    private static final String[] ROW_STYLES = {"even", "odd"};
-    
-    public HTMLElement writeHTML(String caption, String tkey, String tvalue, Map<String,Object>
properties) {
-        HTMLElement html = new HTMLElement("html");
-        html.add(new HTMLElement("head").add(HTMLElement.CSS_JEST));
-        HTMLElement body = new HTMLElement("body");
-        html.add(body);
+    public HTMLDocument createHTML(String title, String tkey, String tvalue, Map<String,Object>
properties) {
+        HTMLDocument html = new HTMLDocument();
+        html.getHead().add(CSS_JEST);
 
-        body.add(new HTMLElement("h1").setBody(caption));
-        HTMLElement table = new HTMLElement("table");
-        HTMLElement header = new HTMLElement("tr").add(
-            new HTMLElement("th").set("style", "width:35%").setBody(tkey), 
-            new HTMLElement("th").set("style", "width:65%").setBody(tvalue));
+        HTMLElement table = new HTMLElement(Tag.table).add(new HTMLElement(Tag.caption).setBody(title));
+        HTMLElement header = new HTMLElement(Tag.tr).add(
+            new HTMLElement(Tag.th).set(STYLE, "width:35%").setBody(tkey), 
+            new HTMLElement(Tag.th).set(STYLE, "width:65%").setBody(tvalue));
         table.add(header);
+        html.getBody().add(table);
         int i = 0;
         for (Map.Entry<String,Object> entry : properties.entrySet()) {
-            i++;
+            HTMLElement row = new HTMLElement(Tag.tr).set(ATTR_CLASS, ++i%2 == 0 ?  CSS_EVEN_ROW
: CSS_ODD_ROW);
             Object value = entry.getValue();
-            String v = "";
-            if (value != null) {
-                v = value.getClass().isArray() ? Arrays.toString((Object[])value) : value.toString();
-            }
-            HTMLElement row = new HTMLElement("tr");
-            String style = i%2 == 0 ?  ROW_STYLES[0] : ROW_STYLES[1]; 
-            row.set("class", style);
+            String v = value == null 
+                     ? Constants.NULL_VALUE 
+                     : value.getClass().isArray() ? Arrays.toString((Object[])value) : value.toString();
             table.add(row.add(
-                new HTMLElement("td").setBody(entry.getKey()), 
-                new HTMLElement("td").setBody(v)));
+                new HTMLElement(Tag.td).setBody(entry.getKey()), 
+                new HTMLElement(Tag.td).setBody(v)));
         }
-        body.add(table);
-        
         return html;
     }
 }

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java?rev=1038004&r1=1038003&r2=1038004&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java
Tue Nov 23 07:27:24 2010
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import static org.apache.openjpa.persistence.jest.Constants.*;
 
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
@@ -35,9 +36,10 @@ import javax.persistence.Query;
  *
  */
 class QueryCommand extends AbstractCommand {
-    private static final List<String> _mandatoryArgs   = Arrays.asList("q");
-    private static final List<String> _validQualifiers = Arrays.asList("format", "plan",
"named", "single", 
-        "first", "max");
+    private static final List<String> _mandatoryArgs   = Arrays.asList(ARG_QUERY);
+    private static final List<String> _validQualifiers = Arrays.asList(
+        QUALIFIER_FORMAT, QUALIFIER_PLAN, QUALIFIER_NAMED, QUALIFIER_SINGLE, 
+        QUALIFIER_FIRSTRESULT, QUALIFIER_MAXRESULT);
     
     @Override
     protected Collection<String> getMandatoryArguments() {
@@ -55,22 +57,23 @@ class QueryCommand extends AbstractComma
 
     @Override
     public void process(JPAServletContext ctx) throws ProcessingException {
-        String spec = getMandatoryArgument("q");
+        String spec = getMandatoryArgument(ARG_QUERY);
         try {
             EntityManager em = ctx.getPersistenceContext();
-            Query query = isBooleanQualifier("named") ? em.createNamedQuery(spec) : em.createQuery(spec);
-            if (hasQualifier("first")) 
-                query.setFirstResult(Integer.parseInt(getQualifier("first")));
-            if (hasQualifier("max")) 
-                query.setMaxResults(Integer.parseInt(getQualifier("max")));
+            Query query = isBooleanQualifier(QUALIFIER_NAMED) ? em.createNamedQuery(spec)
: em.createQuery(spec);
+            if (hasQualifier(QUALIFIER_FIRSTRESULT)) 
+                query.setFirstResult(Integer.parseInt(getQualifier(QUALIFIER_FIRSTRESULT)));
+            if (hasQualifier(QUALIFIER_MAXRESULT)) 
+                query.setMaxResults(Integer.parseInt(getQualifier(QUALIFIER_MAXRESULT)));
             
             Map<String, String> args = getArguments();
             for (Map.Entry<String, String> entry : args.entrySet()) {
                 query.setParameter(entry.getKey(), entry.getValue());
             }
             getObjectFormatter(ctx)
-                .encode(toStateManager(ctx.getPersistenceContext(), isBooleanQualifier("single")

-                 ? Collections.singleton(query.getSingleResult()) : query.getResultList()),
ctx);
+                .writeOut(toStateManager(isBooleanQualifier(QUALIFIER_SINGLE) 
+                 ? Collections.singleton(query.getSingleResult()) : query.getResultList()),

+                 em.getMetamodel(), ctx.getResponse().getWriter());
         } catch (Exception e) {
             throw new ProcessingException(e, _loc.get("query-execution-error", spec));
         }

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java?rev=1038004&r1=1038003&r2=1038004&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java
Tue Nov 23 07:27:24 2010
@@ -19,40 +19,31 @@
 
 package org.apache.openjpa.persistence.jest;
 
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ATTR_ID;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ATTR_KEY_TYPE;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ATTR_MEMBER_TYPE;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ATTR_NAME;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ATTR_NULL;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ATTR_TYPE;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ATTR_VALUE_TYPE;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ELEMENT_ENTRY;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ELEMENT_ENTRY_KEY;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ELEMENT_ENTRY_VALUE;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ELEMENT_INSTANCE;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ELEMENT_MEMBER;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ELEMENT_NULL_REF;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ELEMENT_REF;
-import static org.apache.openjpa.persistence.jest.MetamodelHelper.ELEMENT_ROOT;
+import static org.apache.openjpa.persistence.jest.Constants.*;
 
 import java.io.BufferedReader;
 import java.io.CharArrayWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.PrintWriter;
 import java.io.Reader;
 import java.io.Writer;
+import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.BitSet;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.ManagedType;
 import javax.persistence.metamodel.Metamodel;
+import javax.persistence.metamodel.SingularAttribute;
 import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -87,16 +78,7 @@ import org.w3c.dom.Element;
  * @author Pinaki Poddar
  *
  */
-public class XMLFormatter implements ObjectFormatter {
-    /**
-     * The element/attribute tags declared in <code>jest-instance.xsd</code>
XML schema.
-     */
-        
-
-    static final String W3C_XML_SCHEMA          = "http://www.w3.org/2001/XMLSchema";
-    static final String JAXP_SCHEMA_SOURCE      = "http://java.sun.com/xml/jaxp/properties/schemaSource";
-    static final String JAXP_SCHEMA_LANGUAGE    = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
-    static final String JEST_INSTANCE_XSD       = "jest-instance.xsd";
+public class XMLFormatter implements ObjectFormatter<Document> {
     
     public static final  Schema          _xsd;
     private static final DocumentBuilder _builder;
@@ -107,9 +89,8 @@ public class XMLFormatter implements Obj
             _builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
             _transformer = TransformerFactory.newInstance().newTransformer();
             SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-            InputStream in = XMLFormatter.class.getResourceAsStream(JEST_INSTANCE_XSD);
-            Source schemaFile = new StreamSource(in);
-            _xsd = factory.newSchema(schemaFile);
+            InputStream xsd = XMLFormatter.class.getResourceAsStream(JEST_INSTANCE_XSD);
+            _xsd = factory.newSchema(new StreamSource(xsd));
 
             _transformer.setOutputProperty(OutputKeys.METHOD,     "xml");
             _transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
@@ -126,83 +107,76 @@ public class XMLFormatter implements Obj
         return MIME_TYPE_XML;
     }    
     
-    @Override
-    public void encode(Object obj, JPAServletContext ctx) throws IOException  {
-        if (obj instanceof OpenJPAStateManager) {
-            Document doc = encodeManagedInstance((OpenJPAStateManager)obj, ctx.getPersistenceContext().getMetamodel());
-            try {
-                write(doc, ctx.getResponse().getWriter());
-            } catch (Exception ex) {
-                throw new ProcessingException(ex);
-            }
-        } else {
-            throw new IllegalArgumentException(obj + " is not a managed instance");
-        }
-    }
-
-    @Override
-    public void encode(Collection<?> objs, JPAServletContext ctx) throws IOException
{
-        try {
-            Metamodel model = ctx.getPersistenceContext().getMetamodel();
-            Document doc = encodeManagedInstances((Collection<OpenJPAStateManager>)objs,
model);
-            write(doc, ctx.getResponse().getWriter());
-        } catch (Exception e) {
-            throw new IllegalArgumentException(objs + " is not a managed instance");
-        }
-    }
-    
-    public void write(Document doc, Writer writer) throws Exception {
-        _transformer.transform(new DOMSource(doc), new StreamResult(writer));
-    }
-    
     /**
-     * Encodes a single managed instance in to a XML document according to JEST XML Schema.
-     *  
+     * Encodes the closure of given collection of  managed instance into a new XML document

+     * according to JEST Instance XML Schema.
+     * 
+     * @param sm a collection of managed instances. 
+     * @param parent the parent node to which the new node be attached.
      */
-    public Document encodeManagedInstance(final OpenJPAStateManager sm, Metamodel model)
{
-        return encodeManagedInstances(Collections.singleton(sm), model);
+    public Document encode(final Collection<OpenJPAStateManager> sms, Metamodel model)
{
+        Document doc = newDocument(ELEMENT_ROOT_INSTANCE);
+        Closure closure = new Closure(sms);
+        for (OpenJPAStateManager sm : closure) {
+            encodeManagedInstance(sm, doc.getDocumentElement(), false, model);
+        }
+        return doc;
     }
     
     /**
-     * Encodes the given managed instance into a new XML element as a child of the given
parent node.
+     * Encodes the given meta-model into a new XML document according to JEST Domain XML
Schema.
      * 
-     * @param sm a managed instance, can be null.
-     * @param parent the parent node to which the new node be attached.
+     * @param model a persistent domain model. Must not be null.
      */
-    public Element encodeManagedInstance(final OpenJPAStateManager sm, Element parent, Metamodel
model) {
-        Set<OpenJPAStateManager> visited = new HashSet<OpenJPAStateManager>();
-        Set<OpenJPAStateManager> futures = new HashSet<OpenJPAStateManager>();
-        return encodeManagedInstance(sm, parent, visited, futures, false, model);
+    public Document encode(Metamodel model) {
+        Document doc = newDocument(ELEMENT_DOMAIN);
+        for (ManagedType<?> t : model.getManagedTypes()) {
+            encodeManagedType(t, doc.getDocumentElement());
+        }
+        return doc;
     }
-
+    
     /**
-     * Encodes the given collection of  managed instance into a new XML document according
to JEST XML Schema.
+     * Create a new document with the given root.
      * 
-     * @param sm a managed instance, can be null.
-     * @param parent the parent node to which the new node be attached.
+     * @param rootTag the tag of the root element
+     * 
+     * @return a new XML document
      */
-    public Document encodeManagedInstances(final Collection<OpenJPAStateManager> sms,
Metamodel model) {
+    private Document newDocument(String rootTag) {
         Document doc = _builder.newDocument();
-        Element root = doc.createElement(ELEMENT_ROOT);
+        Element root = doc.createElement(rootTag);
         doc.appendChild(root);
-        if (sms != null) {
-            Set<OpenJPAStateManager> visited = new HashSet<OpenJPAStateManager>();
-            Set<OpenJPAStateManager> futures = new HashSet<OpenJPAStateManager>();
-            for (OpenJPAStateManager sm : sms) {
-                encodeManagedInstance(sm, root, visited, futures, false, model);
-            }
-            while (!futures.isEmpty()) {
-                Set<OpenJPAStateManager> newFutures = new HashSet<OpenJPAStateManager>();
-                for (OpenJPAStateManager sm : futures) {
-                    encodeManagedInstance(sm, root, visited, newFutures, false, model);
-                }
-                futures = newFutures;
-            }
+        String[] nvpairs = new String[] {
+                "xmlns:xsi",                     XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,
+//                "xsi:noNamespaceSchemaLocation", JEST_INSTANCE_XSD,
+                ATTR_VERSION,                       "1.0",
+        };
+        for (int i = 0; i < nvpairs.length; i += 2) {
+            root.setAttribute(nvpairs[i], nvpairs[i+1]);
         }
-        addSchemaToRoot(doc);
         return doc;
     }
+
     
+    @Override
+    public void writeOut(Collection<OpenJPAStateManager> objs, Metamodel model, PrintWriter
writer) throws IOException {
+        write(encode(objs, model), writer, true);
+    }
+    
+    @Override
+    public void writeOut(Metamodel model, PrintWriter writer) throws IOException {
+        write(encode(model), writer, true);
+    }
+    
+    protected void write(Document doc, Writer writer, boolean standalone) throws IOException
{
+        try {
+            _transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, standalone ?
"yes" : "no");
+            _transformer.transform(new DOMSource(doc), new StreamResult(writer));
+        } catch (Exception e) {
+            throw new IOException(e);
+        }
+    }
     
     /**
      * Encodes the closure of a persistent instance into a XML element.
@@ -215,31 +189,16 @@ public class XMLFormatter implements Obj
      * @return the new element. The element has been appended as a child to the given parent
in this method.  
      */
     private Element encodeManagedInstance(final OpenJPAStateManager sm, final Element parent,

-        final Set<OpenJPAStateManager> visited, final Set<OpenJPAStateManager>
futures, boolean isRef, 
-        Metamodel model) {
+         boolean isRef, Metamodel model) {
         if (parent == null)
             throw new InternalException(_loc.get("format-xml-null-parent"));
         Document doc = parent.getOwnerDocument();
         if (doc == null) 
             throw new InternalException(_loc.get("format-xml-null-doc"));
-        if (visited == null)
-            throw new InternalException(_loc.get("format-xml-null-closure"));
         
-        if (sm == null) {
-            return encodeRef(parent, null);
-        }
-        boolean isVisited = visited.contains(sm);
-        if (isRef) {
-            if (!isVisited) {
-                futures.add(sm);
-            }
+        if (sm == null || isRef) {
             return encodeRef(parent, sm);
-        } else if (isVisited) {
-            System.err.println("SM " + ior(sm) + " is not a ref but visited - so not being
printed at all");
-            return null;
-        } 
-        // Neither a ref nor visited before
-        visited.add(sm);
+        }
         Element root = doc.createElement(ELEMENT_INSTANCE);
         parent.appendChild(root);
         root.setAttribute(ATTR_ID, ior(sm));
@@ -305,7 +264,7 @@ public class XMLFormatter implements Obj
                     child.setAttribute(ATTR_NAME, fmd.getName());
                     child.setAttribute(ATTR_TYPE, typeOf(fmd));
                     OpenJPAStateManager other = ctx.getStateManager(value);
-                    encodeManagedInstance(other, child, visited, futures, true, model);
+                    encodeManagedInstance(other, child, true, model);
                     break;
                     
                 case JavaTypes.ARRAY:
@@ -332,7 +291,7 @@ public class XMLFormatter implements Obj
                             if (basic) {
                                 encodeBasic(member, o, o.getClass());
                             } else {
-                                encodeManagedInstance(ctx.getStateManager(o), member, visited,
futures, true, model);
+                                encodeManagedInstance(ctx.getStateManager(o), member, true,
model);
                             }
                         }
                     }
@@ -363,8 +322,7 @@ public class XMLFormatter implements Obj
                             if (basicKey) {
                                 encodeBasic(entryKey, e.getKey(), e.getKey().getClass());
                             } else {
-                                encodeManagedInstance(ctx.getStateManager(e.getKey()), entryKey,
visited, futures, 
-                                    true, model);
+                                encodeManagedInstance(ctx.getStateManager(e.getKey()), entryKey,
true, model);
                             }
                         }
                         if (e.getValue() == null) {
@@ -373,8 +331,7 @@ public class XMLFormatter implements Obj
                             if (basicValue) {
                                 encodeBasic(entryValue, e.getValue(), e.getValue().getClass());
                             } else {
-                                encodeManagedInstance(ctx.getStateManager(e.getValue()),
entryValue, visited, futures, 
-                                    true, model);
+                                encodeManagedInstance(ctx.getStateManager(e.getValue()),
entryValue, true, model);
                             }
                         }
                     }
@@ -418,7 +375,8 @@ public class XMLFormatter implements Obj
         Element ref = parent.getOwnerDocument().createElement(sm == null ? ELEMENT_NULL_REF
: ELEMENT_REF);
         if (sm != null)
             ref.setAttribute(ATTR_ID, ior(sm));
-        ref.setTextContent(" ");
+     // IMPORTANT: for xml transformer not to omit the closing tag otherwise dojo is confused
+        ref.setTextContent(SPACE); 
         parent.appendChild(ref);
         return ref;
     }
@@ -433,7 +391,10 @@ public class XMLFormatter implements Obj
      */
     private void encodeBasic(Element element, Object obj, Class<?> runtimeType) {
         element.setAttribute(ATTR_TYPE, typeOf(runtimeType));
-        element.setTextContent(obj.toString());
+        if (obj instanceof Date)
+            element.setTextContent(dateFormat.format(obj));
+        else 
+            element.setTextContent(obj.toString());
     }
     
     
@@ -465,19 +426,34 @@ public class XMLFormatter implements Obj
         return writer.toString();
     }
     
-    void addSchemaToRoot(Document doc) {
-        Element root = doc.getDocumentElement();
-        
-        String[] nvpairs = new String[] {
-                "xmlns:xsi",                     XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,
-//                "xsi:noNamespaceSchemaLocation", JEST_INSTANCE_XSD,
-                "version",                       "1.0",
-        };
-        for (int i = 0; i < nvpairs.length; i += 2) {
-            root.setAttribute(nvpairs[i], nvpairs[i+1]);
+    
+    private void encodeManagedType(ManagedType<?> type, Element parent) {
+        Document doc = parent.getOwnerDocument();
+        Element root = doc.createElement(type.getPersistenceType().toString().toLowerCase());
+        parent.appendChild(root);
+        root.setAttribute(ATTR_NAME, type.getJavaType().getSimpleName());
+        List<Attribute<?,?>> attributes = MetamodelHelper.getAttributesInOrder(type);
+        for (Attribute<?,?> a : attributes) {
+            String tag = null;
+            if (a instanceof SingularAttribute) {
+                SingularAttribute<?, ?> sa = (SingularAttribute<?, ?>)a;
+                if (sa.isId()) {
+                    tag = ATTR_ID;
+                } else if (sa.isVersion()) {
+                    tag = ATTR_VERSION;
+                } 
+            } 
+            if (tag == null) {
+                tag = a.getPersistentAttributeType().toString().toLowerCase().replace(UNDERSCORE,
DASH);
+            }
+            
+            Element child = doc.createElement(tag);
+            root.appendChild(child);
+            child.setAttribute(ATTR_TYPE, a.getJavaType().getSimpleName());
+            child.setTextContent(a.getName());
         }
     }
-    
+
     void validate(Document doc) throws Exception {
         Validator validator = _xsd.newValidator();
         validator.validate(new DOMSource(doc));

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/instances.js
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/instances.js?rev=1038004&r1=1038003&r2=1038004&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/instances.js
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/instances.js
Tue Nov 23 07:27:24 2010
@@ -18,7 +18,7 @@
  */
 
 /**
- * A JavaScript to render a set of instances as dojo widgets. 
+ * A JavaScript to render a set of instances as dojo widgets.
  */
 dojo.require("dijit.form.Button");
 dojo.require("dijit.TitlePane");
@@ -26,14 +26,14 @@ dojo.ready(function(){
 	// data is supplied in a hidden div with id="data"
     var data = dojo.byId("data");
     
-    // Find all instance node within data node and create TitlePanel for each 
+    // Find all instance node within data node and create TitlePanel for each
     var panels = new Array();
     dojo.query("instance", data).forEach(function(item, index) {
     	  var panel = create(item);
     	  panels[index] = panel;
     });
 
-    // widgets are placed on a empty div with id="canvas" 
+    // widgets are placed on a empty div with id="canvas"
     var canvas = dojo.byId("canvas");
     // assign random location to each panel and add them to canvas
     dojo.forEach(panels, function(item, index) {
@@ -48,20 +48,22 @@ dojo.ready(function(){
 });
 
 /**
- * Creates a dojo Title Pane from a DOM instance node.
- * The pane has the instance id as its title.
- * The content is name and value of each attribute in separate line.
+ * Creates a dojo Title Pane from a DOM instance node. The pane has the instance
+ * id as its title. The content is name and value of each attribute in separate
+ * line.
  * 
- * @param node an instance node
+ * @param node
+ *            an instance node
  * @returns
  */
 function create(node) {
 	var attrs = document.createElement("table");
-	dojo.query('basic, one-to-one', node)
+	dojo.query('id, basic, enum, version', node)
 	    .forEach(function(item) { 
 			var attr = document.createElement("tr");
 			var name = document.createElement("td");
-			name.innerHTML = item.getAttribute("name").bold();
+			name.className = item.nodeName.toLowerCase(); /* May be cross-browser trouble */
+			name.innerHTML = item.getAttribute("name");
 			var value = document.createElement("td");
 			value.innerHTML = item.innerHTML;
 			attr.appendChild(name);
@@ -69,6 +71,50 @@ function create(node) {
 			attrs.appendChild(attr);
 		}
 	);
+	dojo.query('one-to-one, many-to-one', node)
+    .forEach(function(item) { 
+	var attr = document.createElement("tr");
+	var name = document.createElement("td");
+	name.className = item.nodeName.toLowerCase(); /* May be cross-browser trouble */
+	name.innerHTML = item.getAttribute("name");
+	var value = document.createElement("td");
+	var ref = item.getElementsByTagName("ref");
+	if (ref.length>0) {
+		value.innerHTML = ref[0].getAttribute("id");
+		value.className = ref[0].nodeName.toLowerCase();
+		attr.appendChild(name);
+		attr.appendChild(value);
+		attrs.appendChild(attr);
+	}
+    });
+	dojo.query('one-to-many', node)
+    .forEach(function(item) { 
+	var attr = document.createElement("tr");
+	var name = document.createElement("td");
+	name.className = item.nodeName.toLowerCase(); /* May be cross-browser trouble */
+	name.innerHTML = item.getAttribute("name");
+	var value = document.createElement("td");
+	var refs = item.getElementsByTagName("ref");
+	for (var i = 0; i < refs.length; i++) {
+		if (i == 0) {
+			value.innerHTML = refs[i].getAttribute("id");
+			value.className = refs[i].nodeName.toLowerCase();
+			attr.appendChild(name);
+			attr.appendChild(value);
+			attrs.appendChild(attr);
+		} else {
+			var attr = document.createElement("tr");
+			var name = document.createElement("td");
+			var value = document.createElement("td");
+			value.className = refs[i].nodeName.toLowerCase();
+			value.innerHTML = refs[i].getAttribute("id");
+			attr.appendChild(name);
+			attr.appendChild(value);
+			attrs.appendChild(attr);
+		}
+	}
+    }
+);
 	var pane = new dijit.TitlePane({
 			title: node.getAttribute("id"), 
 			content:attrs

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css?rev=1038004&r1=1038003&r2=1038004&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css
Tue Nov 23 07:27:24 2010
@@ -40,42 +40,52 @@
  * --------------------------------------------------------------------- */
 .tag {
 	color:green;
-	font:"Courier New";
+	font-family:"Courier New";
 	font-weight:bold;
 }
 /** -----------------------------------------------------------------------
- * Table
+ * Data Table used for Tabular HTML
  * --------------------------------------------------------------------- */
-table {
+table.data td th {
 	width : 70%;
 	border-collapse:collapse;
-}
-table td th {
-	padding:1em 10em 2m 10em;
 	border:2px solid black;
+	margin: 10px 10px 10px 10px;
+}
+tr {
+	vertical-align:top;
 }
 th {
-   background-color:black;
+   background-color:#444444;
    color:white;
+   text-align:left;
+}
+caption {
+	background-color:#000000;
+    color:white;
+	font-size:1.2em;
+	font-weight:bold;
+	padding:5px 5px 5px 5px;
 }
 /** -----------------------------------------------------------------------
  * Alternate Table Row
  * --------------------------------------------------------------------- */
 tr.even td {
    background-color: #FFFFFF; color: black;
-   padding:2x 20px;
-	border:2px solid black;
+   padding:2px 20px;
+   border:2px solid black;
+	vertical-align:top;
 }
 tr.odd td {
    background-color: #EEEEEE; color: black;
-   padding:2x 20px;
-	border:2px solid black;
+   padding:2px 20px;
+   border:2px solid black;
+	vertical-align:top;
 }
 
 /** -----------------------------------------------------------------------
  * Hyperlinks
  * --------------------------------------------------------------------- */
-
 a {
 	target:_blank;
 }
@@ -86,6 +96,14 @@ a {
 	font-size:1.1em;
 	font-family:"Courier New", Arial;
 }
+
+/** -----------------------------------------------------------------------
+ * Paragraph with smaller line breaks 
+ * --------------------------------------------------------------------- */
+p.small {
+	line-height:60%;
+}
+
 /** -----------------------------------------------------------------------
  * Error Page 
  * --------------------------------------------------------------------- */
@@ -99,4 +117,30 @@ a {
 	font-size:1.2em;
 }
 
+/*
+ *  JPA styles
+*/
+.id {
+	color:red;
+	font-weight:bold;
+}
+.enum {
+	color:magenta;
+	font-weight:bold;
+}
+.basic {
+	color:green;
+	font-weight:bold;
+}
+.one-to-one {
+	color:lightblue;
+	font-weight:bold;
+}
+.one-to-many {
+	color:darkblue;
+	font-weight:bold;
+}
 
+.ref {
+	color : blue;
+}

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/localizer.properties?rev=1038004&r1=1038003&r2=1038004&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/localizer.properties
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/localizer.properties
Tue Nov 23 07:27:24 2010
@@ -45,6 +45,7 @@ parse-less-argument: {0} command must ha
 format-xml-null-parent: A null XML parent element encountered during serialization 
 format-xml-null-doc: Given parent element is not part of XML document
 format-xml-null-closure: Set of visited instances can not be null for serialization
-
+format-not-supported: format {0} in command {1} is not registered. Available formats are
{2}.
 
 properties-caption: Configuration of {0} Persistence Unit 
+entity-not-found: Resource of type {0} with identifier {1} is not found.
\ No newline at end of file



Mime
View raw message