You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2003/12/27 23:10:40 UTC
cvs commit: ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl JAXBSGFactory.java
jochen 2003/12/27 14:10:40
Modified: src/jaxme/org/apache/ws/jaxme/generator Generator.java
src/jaxme/org/apache/ws/jaxme/generator/impl
GeneratorImpl.java
src/jaxme/org/apache/ws/jaxme/generator/sg/impl
JAXBSGFactory.java
Log:
A user may now supply an EntityResolver.
Revision Changes Path
1.2 +12 -1 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/Generator.java
Index: Generator.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/Generator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Generator.java 23 Sep 2003 12:34:48 -0000 1.1
+++ Generator.java 27 Dec 2003 22:10:39 -0000 1.2
@@ -52,6 +52,7 @@
import java.net.URL;
import org.apache.ws.jaxme.generator.sg.SchemaSG;
+import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
/** <p>The Generator is a frontend for working with the
@@ -129,4 +130,14 @@
/** <p>Returns a key for getting and setting custom data.</p>
*/
public String getKey();
+
+ /** <p>Sets the {@link EntityResolver} being used to import external
+ * schemata.</p>
+ */
+ public void setEntityResolver(EntityResolver pEntityResolver);
+
+ /** <p>Returns the {@link EntityResolver} being used to import external
+ * schemata.</p>
+ */
+ public EntityResolver getEntityResolver();
}
1.2 +16 -0 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/impl/GeneratorImpl.java
Index: GeneratorImpl.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/impl/GeneratorImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GeneratorImpl.java 23 Sep 2003 12:34:52 -0000 1.1
+++ GeneratorImpl.java 27 Dec 2003 22:10:39 -0000 1.2
@@ -58,6 +58,7 @@
import org.apache.ws.jaxme.generator.sg.SchemaSG;
import org.apache.ws.jaxme.logging.Logger;
import org.apache.ws.jaxme.logging.LoggerAccess;
+import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
@@ -74,7 +75,22 @@
private Map properties = new HashMap();
private int nextKey;
private boolean isValidating, isForcingOverwrite, isSettingReadOnly;
+ private EntityResolver entityResolver;
+ /** <p>Sets the {@link EntityResolver} being used to import external
+ * schemata.</p>
+ */
+ public void setEntityResolver(EntityResolver pEntityResolver) {
+ entityResolver = pEntityResolver;
+ }
+
+ /** <p>Returns the {@link EntityResolver} being used to import external
+ * schemata.</p>
+ */
+ public EntityResolver getEntityResolver() {
+ return entityResolver;
+ }
+
/** <p>Returns whether the generator is forcing an overwrite of files.</p>
*/
public boolean isForcingOverwrite() {
1.4 +207 -193 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBSGFactory.java
Index: JAXBSGFactory.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBSGFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JAXBSGFactory.java 20 Oct 2003 20:32:43 -0000 1.3
+++ JAXBSGFactory.java 27 Dec 2003 22:10:40 -0000 1.4
@@ -53,6 +53,8 @@
import java.util.List;
import java.util.Map;
+import javax.xml.parsers.ParserConfigurationException;
+
import org.apache.ws.jaxme.generator.Generator;
import org.apache.ws.jaxme.generator.sg.Context;
import org.apache.ws.jaxme.generator.sg.Facet;
@@ -75,10 +77,13 @@
import org.apache.ws.jaxme.xs.XSSchema;
import org.apache.ws.jaxme.xs.XSType;
import org.apache.ws.jaxme.xs.jaxb.impl.JAXBParser;
+import org.apache.ws.jaxme.xs.jaxb.impl.JAXBXsObjectFactoryImpl;
import org.apache.ws.jaxme.xs.parser.XSContext;
import org.apache.ws.jaxme.xs.xml.XsObjectFactory;
import org.apache.ws.jaxme.xs.xml.XsQName;
+import org.xml.sax.EntityResolver;
import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
@@ -86,197 +91,206 @@
* @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
*/
public class JAXBSGFactory implements SGFactoryChain {
- private final static Logger log = LoggerAccess.getLogger(JAXBSGFactory.class);
- private final Generator generator;
- private SchemaSG schemaSG;
- private Map groups = new HashMap();
- private Map objects = new HashMap();
- private Map types = new HashMap();
- private List groupsByOrder = new ArrayList();
- private List objectsByOrder = new ArrayList();
- private List typesByOrder = new ArrayList();
-
- public JAXBSGFactory(Generator pGenerator) {
- generator = pGenerator;
- }
-
- public void init(SGFactory pController) {
- }
-
- public Generator getGenerator(SGFactory pController) {
- return generator;
- }
-
- public GroupSG getGroupSG(SGFactory pController, XSGroup pGroup) throws SAXException {
- GroupSG result = (GroupSG) groups.get(pGroup);
- if (result == null) {
- result = pController.newGroupSG(pGroup);
- groups.put(pGroup, result);
- groupsByOrder.add(result);
- result.init();
- }
- return result;
- }
-
- public GroupSG newGroupSG(SGFactory pController, XSGroup pGroup) throws SAXException {
- if (schemaSG == null) {
- throw new IllegalStateException("A schema has not yet been created");
- }
- return new GroupSGImpl(new JAXBGroupSG(pController, schemaSG, pGroup));
- }
-
- public GroupSG getGroupSG(SGFactory pController, XSGroup pGroup, Context pClassContext) throws SAXException {
- GroupSG result = pController.newGroupSG(pGroup, pClassContext);
- result.init();
- groupsByOrder.add(result);
- return result;
- }
-
- public GroupSG newGroupSG(SGFactory pController, XSGroup pGroup, Context pClassContext) throws SAXException {
- if (schemaSG == null) {
- throw new IllegalStateException("A schema has not yet been created");
- }
- return new GroupSGImpl(new JAXBGroupSG(pController, schemaSG, pGroup, pClassContext));
- }
-
-
- public Object newObjectSG(SGFactory pController, XSElement pElement) throws SAXException {
- if (schemaSG == null) {
- throw new IllegalStateException("A schema has not yet been created.");
- }
- return new JAXBObjectSG(pController, schemaSG, pElement);
- }
-
- public ObjectSG getObjectSG(SGFactory pController, XSElement pElement) throws SAXException {
- ObjectSG result = (ObjectSG) objects.get(pElement);
- if (result == null) {
- ObjectSGChain chain = (ObjectSGChain) pController.newObjectSG(pElement);
- result = new ObjectSGImpl(chain);
- objects.put(pElement, result);
- objectsByOrder.add(result);
- result.init();
- }
- return result;
- }
-
- public Object newObjectSG(SGFactory pController, XSElement pElement, Context pContext) throws SAXException {
- if (schemaSG == null) {
- throw new IllegalStateException("A schema has not yet been created.");
- }
- return new JAXBObjectSG(pController, schemaSG, pElement, pContext);
- }
-
- public ObjectSG getObjectSG(SGFactory pController, XSElement pElement, Context pContext) throws SAXException {
- ObjectSGChain chain = (ObjectSGChain) pController.newObjectSG(pElement, pContext);
- ObjectSG result = new ObjectSGImpl(chain);
- result.init();
- return result;
- }
-
- public SchemaSG getSchemaSG(SGFactory pController, XSSchema pSchema) throws SAXException {
- if (schemaSG == null) {
- SchemaSGChain chain = (SchemaSGChain) pController.newSchemaSG(pSchema);
- schemaSG = new SchemaSGImpl(chain);
- schemaSG.init();
- }
- return schemaSG;
- }
-
- public SchemaSG getSchemaSG(SGFactory pController) {
- if (schemaSG == null) {
- throw new IllegalStateException("A factory has not yet been created.");
- }
- return schemaSG;
- }
-
- public Object newSchemaSG(SGFactory pController, XSSchema pSchema) throws SAXException {
- return new JAXBSchemaSG(pController, pSchema);
- }
-
- public TypeSG getTypeSG(SGFactory pController, XSType pType) throws SAXException {
- final String mName = "getTypeSG(XSType)";
- TypeSG result = (TypeSG) types.get(pType);
- if (result == null) {
- log.finest(mName, "->", pType.getName());
- TypeSGChain chain = (TypeSGChain) pController.newTypeSG(pType);
- result = new TypeSGImpl(chain);
- types.put(pType, result);
- typesByOrder.add(result);
- result.init();
- log.finest(mName, "<-", new Object[]{chain, result});
- }
- return result;
- }
-
- public Object newTypeSG(SGFactory pController, XSType pType) throws SAXException {
- if (schemaSG == null) {
- throw new IllegalStateException("A schema has not yet been created");
- }
- return new JAXBTypeSG(pController, schemaSG, pType);
- }
-
- public TypeSG getTypeSG(SGFactory pController, XSType pType, Context pClassContext, XsQName pName) throws SAXException {
- final String mName = "getTypeSG(XSType,ClassContext)";
- log.finest(mName, "->", new Object[]{pType, pClassContext});
- TypeSGChain chain = (TypeSGChain) pController.newTypeSG(pType, pClassContext, pName);
- TypeSG result = new TypeSGImpl(chain);
- typesByOrder.add(result);
- result.init();
- log.finest(mName, "<-", new Object[]{chain, result});
- return result;
- }
-
- public Object newTypeSG(SGFactory pController, XSType pType, Context pClassContext, XsQName pName) throws SAXException {
- if (schemaSG == null) {
- throw new IllegalStateException("A schema has not yet been created");
- }
- return new JAXBTypeSG(pController, schemaSG, pType, pClassContext, pName);
- }
-
- public Object newTypeSG(SGFactory pController, XSType pType, XsQName pName) throws SAXException {
- if (schemaSG == null) {
- throw new IllegalStateException("A schema has not yet been created");
- }
- return new JAXBTypeSG(pController, schemaSG, pType, pName);
- }
-
- public TypeSG getTypeSG(SGFactory pController, XSType pType, XsQName pName) throws SAXException {
- TypeSGChain chain = (TypeSGChain) pController.newTypeSG(pType, pName);
- TypeSG result = new TypeSGImpl(chain);
- typesByOrder.add(result);
- result.init();
- return result;
- }
-
- public XSParser newXSParser(SGFactory pController) throws SAXException {
- XSParser parser = new JAXBParser();
- XSContext context = parser.getContext();
- context.setXsObjectFactory(pController.newXsObjectFactory());
- context.setXSObjectFactory(pController.newXSObjectFactory());
- return parser;
- }
-
- public Facet newFacet(SGFactory pController, XSType pType, XSEnumeration[] pEnumerations) throws SAXException {
- return new FacetImpl(pType, pEnumerations);
- }
-
- public TypeSG[] getTypes(SGFactory pController) {
- return (TypeSG[]) typesByOrder.toArray(new TypeSG[typesByOrder.size()]);
- }
-
- public GroupSG[] getGroups(SGFactory pController) {
- return (GroupSG[]) groupsByOrder.toArray(new GroupSG[groupsByOrder.size()]);
- }
-
- public ObjectSG[] getObjects(SGFactory pController) {
- return (ObjectSG[]) objectsByOrder.toArray(new ObjectSG[objectsByOrder.size()]);
- }
-
- public XsObjectFactory newXsObjectFactory(SGFactory pController) throws SAXException {
- return JAXBParser.JAXB_XS_OBJECT_FACTORY;
- }
-
- public XSObjectFactory newXSObjectFactory(SGFactory pController) throws SAXException {
- return JAXBParser.JAXB_OBJECT_FACTORY;
- }
+ private final static Logger log = LoggerAccess.getLogger(JAXBSGFactory.class);
+ private final Generator generator;
+ private SchemaSG schemaSG;
+ private Map groups = new HashMap();
+ private Map objects = new HashMap();
+ private Map types = new HashMap();
+ private List groupsByOrder = new ArrayList();
+ private List objectsByOrder = new ArrayList();
+ private List typesByOrder = new ArrayList();
+
+ public JAXBSGFactory(Generator pGenerator) {
+ generator = pGenerator;
+ }
+
+ public void init(SGFactory pController) {
+ }
+
+ public Generator getGenerator(SGFactory pController) {
+ return generator;
+ }
+
+ public GroupSG getGroupSG(SGFactory pController, XSGroup pGroup) throws SAXException {
+ GroupSG result = (GroupSG) groups.get(pGroup);
+ if (result == null) {
+ result = pController.newGroupSG(pGroup);
+ groups.put(pGroup, result);
+ groupsByOrder.add(result);
+ result.init();
+ }
+ return result;
+ }
+
+ public GroupSG newGroupSG(SGFactory pController, XSGroup pGroup) throws SAXException {
+ if (schemaSG == null) {
+ throw new IllegalStateException("A schema has not yet been created");
+ }
+ return new GroupSGImpl(new JAXBGroupSG(pController, schemaSG, pGroup));
+ }
+
+ public GroupSG getGroupSG(SGFactory pController, XSGroup pGroup, Context pClassContext) throws SAXException {
+ GroupSG result = pController.newGroupSG(pGroup, pClassContext);
+ result.init();
+ groupsByOrder.add(result);
+ return result;
+ }
+
+ public GroupSG newGroupSG(SGFactory pController, XSGroup pGroup, Context pClassContext) throws SAXException {
+ if (schemaSG == null) {
+ throw new IllegalStateException("A schema has not yet been created");
+ }
+ return new GroupSGImpl(new JAXBGroupSG(pController, schemaSG, pGroup, pClassContext));
+ }
+
+
+ public Object newObjectSG(SGFactory pController, XSElement pElement) throws SAXException {
+ if (schemaSG == null) {
+ throw new IllegalStateException("A schema has not yet been created.");
+ }
+ return new JAXBObjectSG(pController, schemaSG, pElement);
+ }
+
+ public ObjectSG getObjectSG(SGFactory pController, XSElement pElement) throws SAXException {
+ ObjectSG result = (ObjectSG) objects.get(pElement);
+ if (result == null) {
+ ObjectSGChain chain = (ObjectSGChain) pController.newObjectSG(pElement);
+ result = new ObjectSGImpl(chain);
+ objects.put(pElement, result);
+ objectsByOrder.add(result);
+ result.init();
+ }
+ return result;
+ }
+
+ public Object newObjectSG(SGFactory pController, XSElement pElement, Context pContext) throws SAXException {
+ if (schemaSG == null) {
+ throw new IllegalStateException("A schema has not yet been created.");
+ }
+ return new JAXBObjectSG(pController, schemaSG, pElement, pContext);
+ }
+
+ public ObjectSG getObjectSG(SGFactory pController, XSElement pElement, Context pContext) throws SAXException {
+ ObjectSGChain chain = (ObjectSGChain) pController.newObjectSG(pElement, pContext);
+ ObjectSG result = new ObjectSGImpl(chain);
+ result.init();
+ return result;
+ }
+
+ public SchemaSG getSchemaSG(SGFactory pController, XSSchema pSchema) throws SAXException {
+ if (schemaSG == null) {
+ SchemaSGChain chain = (SchemaSGChain) pController.newSchemaSG(pSchema);
+ schemaSG = new SchemaSGImpl(chain);
+ schemaSG.init();
+ }
+ return schemaSG;
+ }
+
+ public SchemaSG getSchemaSG(SGFactory pController) {
+ if (schemaSG == null) {
+ throw new IllegalStateException("A factory has not yet been created.");
+ }
+ return schemaSG;
+ }
+
+ public Object newSchemaSG(SGFactory pController, XSSchema pSchema) throws SAXException {
+ return new JAXBSchemaSG(pController, pSchema);
+ }
+
+ public TypeSG getTypeSG(SGFactory pController, XSType pType) throws SAXException {
+ final String mName = "getTypeSG(XSType)";
+ TypeSG result = (TypeSG) types.get(pType);
+ if (result == null) {
+ log.finest(mName, "->", pType.getName());
+ TypeSGChain chain = (TypeSGChain) pController.newTypeSG(pType);
+ result = new TypeSGImpl(chain);
+ types.put(pType, result);
+ typesByOrder.add(result);
+ result.init();
+ log.finest(mName, "<-", new Object[]{chain, result});
+ }
+ return result;
+ }
+
+ public Object newTypeSG(SGFactory pController, XSType pType) throws SAXException {
+ if (schemaSG == null) {
+ throw new IllegalStateException("A schema has not yet been created");
+ }
+ return new JAXBTypeSG(pController, schemaSG, pType);
+ }
+
+ public TypeSG getTypeSG(SGFactory pController, XSType pType, Context pClassContext, XsQName pName) throws SAXException {
+ final String mName = "getTypeSG(XSType,ClassContext)";
+ log.finest(mName, "->", new Object[]{pType, pClassContext});
+ TypeSGChain chain = (TypeSGChain) pController.newTypeSG(pType, pClassContext, pName);
+ TypeSG result = new TypeSGImpl(chain);
+ typesByOrder.add(result);
+ result.init();
+ log.finest(mName, "<-", new Object[]{chain, result});
+ return result;
+ }
+
+ public Object newTypeSG(SGFactory pController, XSType pType, Context pClassContext, XsQName pName) throws SAXException {
+ if (schemaSG == null) {
+ throw new IllegalStateException("A schema has not yet been created");
+ }
+ return new JAXBTypeSG(pController, schemaSG, pType, pClassContext, pName);
+ }
+
+ public Object newTypeSG(SGFactory pController, XSType pType, XsQName pName) throws SAXException {
+ if (schemaSG == null) {
+ throw new IllegalStateException("A schema has not yet been created");
+ }
+ return new JAXBTypeSG(pController, schemaSG, pType, pName);
+ }
+
+ public TypeSG getTypeSG(SGFactory pController, XSType pType, XsQName pName) throws SAXException {
+ TypeSGChain chain = (TypeSGChain) pController.newTypeSG(pType, pName);
+ TypeSG result = new TypeSGImpl(chain);
+ typesByOrder.add(result);
+ result.init();
+ return result;
+ }
+
+ public XSParser newXSParser(SGFactory pController) throws SAXException {
+ XSParser parser = new JAXBParser();
+ XSContext context = parser.getContext();
+ context.setXsObjectFactory(pController.newXsObjectFactory());
+ context.setXSObjectFactory(pController.newXSObjectFactory());
+ return parser;
+ }
+
+ public Facet newFacet(SGFactory pController, XSType pType, XSEnumeration[] pEnumerations) throws SAXException {
+ return new FacetImpl(pType, pEnumerations);
+ }
+
+ public TypeSG[] getTypes(SGFactory pController) {
+ return (TypeSG[]) typesByOrder.toArray(new TypeSG[typesByOrder.size()]);
+ }
+
+ public GroupSG[] getGroups(SGFactory pController) {
+ return (GroupSG[]) groupsByOrder.toArray(new GroupSG[groupsByOrder.size()]);
+ }
+
+ public ObjectSG[] getObjects(SGFactory pController) {
+ return (ObjectSG[]) objectsByOrder.toArray(new ObjectSG[objectsByOrder.size()]);
+ }
+
+ public XsObjectFactory newXsObjectFactory(SGFactory pController) throws SAXException {
+ return new JAXBXsObjectFactoryImpl(){
+ public XMLReader newXMLReader(boolean pValidating) throws ParserConfigurationException, SAXException{
+ XMLReader xr = super.newXMLReader(pValidating);
+ EntityResolver entityResolver = generator.getEntityResolver();
+ if (entityResolver != null) {
+ xr.setEntityResolver(entityResolver);
+ }
+ return xr;
+ }
+ };
+ }
+
+ public XSObjectFactory newXSObjectFactory(SGFactory pController) throws SAXException {
+ return JAXBParser.JAXB_OBJECT_FACTORY;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org