incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r293153 - in /incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl: DigesterMapperImpl.java DisgesterDescriptorReader.java
Date Sun, 02 Oct 2005 20:00:49 GMT
Author: clombart
Date: Sun Oct  2 13:00:45 2005
New Revision: 293153

URL: http://svn.apache.org/viewcvs?rev=293153&view=rev
Log:
Apply patch provided by Costin - Support inpuststream

Modified:
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DisgesterDescriptorReader.java

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java?rev=293153&r1=293152&r2=293153&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
Sun Oct  2 13:00:45 2005
@@ -1,67 +1,74 @@
-/*
- * Copyright 2000-2004 The Apache Software Foundation.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.portals.graffito.jcr.mapper.impl;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.portals.graffito.jcr.exception.JcrMappingException;
-import org.apache.portals.graffito.jcr.mapper.Mapper;
-import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
-import org.apache.portals.graffito.jcr.mapper.model.MappingDescriptor;
-
-/**
- *
- * Digester implementation for {@link org.apache.portals.graffito.jcr.mapper.Mapper}
- * 
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe
</a>
- * @version $Id: Exp $
- */
-public class DigesterMapperImpl implements Mapper
-{    
-    private MappingDescriptor mappingDescriptor;
-    private Log log = LogFactory.getLog(DigesterMapperImpl.class); 
-    
-    /**
-     * Constructor
-     *  
-     * @param xmlFile
-     * @throws JcrMappingException
-     */
-    public DigesterMapperImpl(String xmlFile) throws JcrMappingException
-    {
-        log.info("Read the xml mapping file : " +  xmlFile);
-        mappingDescriptor = DisgesterDescriptorReader.loadClassDescriptors(xmlFile);
-    }
-
-    /**
-     * Get the mapping defition to be used for a specific java bean
-     * @param clazz The java bean class
-     * @return The mapping class found for the desired java bean class 
-     * @throws JcrMappingException
-     */
-    public ClassDescriptor getClassDescriptor(Class clazz) throws JcrMappingException
-    {        
-        try
-        {
-            return mappingDescriptor.getClassDescriptor(clazz.getName());
-        }
-        catch (Exception e)
-        {
-            throw new JcrMappingException("Impossible to retrieve the Mapping class for "
+ clazz, e);
-        }
-    }
-
-}
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.mapper.impl;
+
+import java.io.InputStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.MappingDescriptor;
+
+/**
+ *
+ * Digester implementation for {@link org.apache.portals.graffito.jcr.mapper.Mapper}
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe
</a>
+ * @version $Id: Exp $
+ */
+public class DigesterMapperImpl implements Mapper
+{    
+    private MappingDescriptor mappingDescriptor;
+    private Log log = LogFactory.getLog(DigesterMapperImpl.class); 
+    
+    /**
+     * Constructor
+     *  
+     * @param xmlFile
+     * @throws JcrMappingException
+     */
+    public DigesterMapperImpl(String xmlFile) throws JcrMappingException
+    {
+        log.info("Read the xml mapping file : " +  xmlFile);
+        mappingDescriptor = DisgesterDescriptorReader.loadClassDescriptors(xmlFile);
+    }
+    
+    public DigesterMapperImpl(InputStream stream) throws JcrMappingException
+    {
+        log.info("Read the input stream : " +  stream);
+        mappingDescriptor = DisgesterDescriptorReader.loadClassDescriptors(stream);
+    }
+
+    /**
+     * Get the mapping defition to be used for a specific java bean
+     * @param clazz The java bean class
+     * @return The mapping class found for the desired java bean class 
+     * @throws JcrMappingException
+     */
+    public ClassDescriptor getClassDescriptor(Class clazz) throws JcrMappingException
+    {        
+        try
+        {
+            return mappingDescriptor.getClassDescriptor(clazz.getName());
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to retrieve the Mapping class for "
+ clazz, e);
+        }
+    }
+}

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DisgesterDescriptorReader.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DisgesterDescriptorReader.java?rev=293153&r1=293152&r2=293153&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DisgesterDescriptorReader.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DisgesterDescriptorReader.java
Sun Oct  2 13:00:45 2005
@@ -1,108 +1,110 @@
-/*
- * Copyright 2000-2004 The Apache Software Foundation.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.portals.graffito.jcr.mapper.impl;
-
-import java.io.File;
-
-import org.apache.commons.digester.Digester;
-import org.apache.portals.graffito.jcr.exception.JcrMappingException;
-import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
-import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
-import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
-import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor;
-import org.apache.portals.graffito.jcr.mapper.model.MappingDescriptor;
-
-/**
- * This class read the xml mapping file and load all class descriptors into memory (object
graph)
- * 
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe
</a>
- * @version $Id: Exp $
- */
-public class DisgesterDescriptorReader
-{
-    /**
-     * Load all class descriptors found in the xml mapping file.
-     * 
-     * @param xmlFile the xml mapping file reference
-     * @return a {@link MappingDescriptor}
-     * 
-     * @throws JcrMappingException when it is not possible to read the xml mapping file
-     * 
-     */
-    public static MappingDescriptor loadClassDescriptors(String xmlFile) throws JcrMappingException
-    {
-        try
-        {
-            Digester digester = new Digester();
-            digester.setValidating(true);
-
-            digester.addObjectCreate("graffito-jcr", MappingDescriptor.class);
-
-            // --------------------------------------------------------------------------------
-            // Rules used for the class-descriptor element
-            // --------------------------------------------------------------------------------
-
-            digester.addObjectCreate("graffito-jcr/class-descriptor", ClassDescriptor.class);
-            digester.addSetProperties("graffito-jcr/class-descriptor", "className", "className");
-            digester.addSetProperties("graffito-jcr/class-descriptor", "jcrNodeType", "jcrNodeType");
-            
-            digester.addSetNext("graffito-jcr/class-descriptor", "addClassDescriptor");
-
-            // --------------------------------------------------------------------------------
-            // Rules used for the field-descriptor element
-            // --------------------------------------------------------------------------------
-
-            digester.addObjectCreate("graffito-jcr/class-descriptor/field-descriptor", FieldDescriptor.class);
-            digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "fieldName",
"fieldName");
-            digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrName",
"jcrName");
-            digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "id",
"id");
-            digester.addSetNext("graffito-jcr/class-descriptor/field-descriptor", "addFieldDescriptor");
-            
-            // --------------------------------------------------------------------------------
-            // Rules used for the bean-descriptor element
-            // --------------------------------------------------------------------------------
-
-            digester.addObjectCreate("graffito-jcr/class-descriptor/bean-descriptor", BeanDescriptor.class);
-            digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "fieldName",
"fieldName");
-            digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "jcrName",
"jcrName");
-            digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "proxy",
"proxy");
-            digester.addSetNext("graffito-jcr/class-descriptor/bean-descriptor", "addBeanDescriptor");
-
-            // --------------------------------------------------------------------------------
-            // Rules used for the collection-descriptor element
-            // --------------------------------------------------------------------------------
-
-            digester.addObjectCreate("graffito-jcr/class-descriptor/collection-descriptor",
CollectionDescriptor.class);
-            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"fieldName", "fieldName");
-            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"jcrName", "jcrName");
-            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"proxy", "proxy");            
-            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"elementClassName", "elementClassName");
-            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"collectionConverter", "collectionConverterClassName");
-            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"collectionClassName", "collectionClassName");
-            digester.addSetNext("graffito-jcr/class-descriptor/collection-descriptor", "addCollectionDescriptor");
-            
-            
-            File input = new File(xmlFile);
-            MappingDescriptor mappingDescriptor= (MappingDescriptor)digester.parse( input
);
-            return mappingDescriptor;
-        }
-        catch (Exception e)
-        {            
-            throw new JcrMappingException("Impossible to read the xml mapping file", e);
-        }
-    }
-}
-
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.mapper.impl;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import org.apache.commons.digester.Digester;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.MappingDescriptor;
+
+/**
+ * This class read the xml mapping file and load all class descriptors into memory (object
graph)
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe
</a>
+ * @version $Id: Exp $
+ */
+public class DisgesterDescriptorReader {
+    /**
+     * Load all class descriptors found in the xml mapping file.
+     * 
+     * @param xmlFile the xml mapping file reference
+     * @return a {@link MappingDescriptor}
+     * 
+     * @throws JcrMappingException when it is not possible to read the xml mapping file
+     * 
+     */
+    public static MappingDescriptor loadClassDescriptors(InputStream stream) throws JcrMappingException
{
+        try {
+            Digester digester = new Digester();
+            digester.setValidating(true);
+
+            digester.addObjectCreate("graffito-jcr", MappingDescriptor.class);
+
+            // --------------------------------------------------------------------------------
+            // Rules used for the class-descriptor element
+            // --------------------------------------------------------------------------------
+
+            digester.addObjectCreate("graffito-jcr/class-descriptor", ClassDescriptor.class);
+            digester.addSetProperties("graffito-jcr/class-descriptor", "className", "className");
+            digester.addSetProperties("graffito-jcr/class-descriptor", "jcrNodeType", "jcrNodeType");
+
+            digester.addSetNext("graffito-jcr/class-descriptor", "addClassDescriptor");
+
+            // --------------------------------------------------------------------------------
+            // Rules used for the field-descriptor element
+            // --------------------------------------------------------------------------------
+
+            digester.addObjectCreate("graffito-jcr/class-descriptor/field-descriptor", FieldDescriptor.class);
+            digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "fieldName",
"fieldName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrName",
"jcrName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "id",
"id");
+            digester.addSetNext("graffito-jcr/class-descriptor/field-descriptor", "addFieldDescriptor");
+
+            // --------------------------------------------------------------------------------
+            // Rules used for the bean-descriptor element
+            // --------------------------------------------------------------------------------
+
+            digester.addObjectCreate("graffito-jcr/class-descriptor/bean-descriptor", BeanDescriptor.class);
+            digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "fieldName",
"fieldName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "jcrName",
"jcrName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "proxy",
"proxy");
+            digester.addSetNext("graffito-jcr/class-descriptor/bean-descriptor", "addBeanDescriptor");
+
+            // --------------------------------------------------------------------------------
+            // Rules used for the collection-descriptor element
+            // --------------------------------------------------------------------------------
+
+            digester.addObjectCreate("graffito-jcr/class-descriptor/collection-descriptor",
CollectionDescriptor.class);
+            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"fieldName", "fieldName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"jcrName", "jcrName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"proxy", "proxy");
+            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"elementClassName", "elementClassName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"collectionConverter", "collectionConverterClassName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"collectionClassName", "collectionClassName");
+            digester.addSetNext("graffito-jcr/class-descriptor/collection-descriptor", "addCollectionDescriptor");
+
+            MappingDescriptor mappingDescriptor = (MappingDescriptor) digester.parse(stream);
+            return mappingDescriptor;
+        } catch (Exception e) {
+            throw new JcrMappingException("Impossible to read the xml mapping file", e);
+        }
+    }
+
+    public static MappingDescriptor loadClassDescriptors(String xmlFile) throws JcrMappingException
{
+        try {
+            return loadClassDescriptors(new FileInputStream(xmlFile));
+        } catch (FileNotFoundException e) {
+            throw new JcrMappingException(e);
+        }
+    }
+}



Mime
View raw message