vgritsenko 2003/01/24 19:02:11 Modified: src/scratchpad/src/org/apache/cocoon/components/axis SoapServerImpl.java src/scratchpad/src/org/apache/cocoon/components/source/impl XMLDBSourceFactory.java src/scratchpad/src/org/apache/cocoon/transformation CastorTransformer.java Log: conf in configure() never null Revision Changes Path 1.8 +10 -17 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/axis/SoapServerImpl.java Index: SoapServerImpl.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/axis/SoapServerImpl.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SoapServerImpl.java 15 Jan 2003 10:39:35 -0000 1.7 +++ SoapServerImpl.java 25 Jan 2003 03:02:10 -0000 1.8 @@ -234,25 +234,18 @@ public void configure(final Configuration config) throws ConfigurationException { - try - { - if (config != null) - { - setServerConfig(config); - setAttachmentDir(config); - setJWSDir(config); - setSecurityProvider(config); - setTransportName(config); - setManagedServices(config); - } + try { + setServerConfig(config); + setAttachmentDir(config); + setJWSDir(config); + setSecurityProvider(config); + setTransportName(config); + setManagedServices(config); - if (getLogger().isDebugEnabled()) - { + if (getLogger().isDebugEnabled()) { getLogger().debug("SoapServerImpl.configure() complete"); } - } - catch (final Exception e) - { + } catch (final Exception e) { throw new ConfigurationException("Error during configuration", e); } } 1.6 +23 -36 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/impl/XMLDBSourceFactory.java Index: XMLDBSourceFactory.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/impl/XMLDBSourceFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- XMLDBSourceFactory.java 10 Jan 2003 20:55:30 -0000 1.5 +++ XMLDBSourceFactory.java 25 Jan 2003 03:02:11 -0000 1.6 @@ -99,45 +99,32 @@ public void configure(final Configuration conf) throws ConfigurationException { - if (conf != null) { + driverMap = new HashMap(); - driverMap = new HashMap(); + Configuration[] xmldbConfigs = conf.getChildren("driver"); + for (int i = 0; i < xmldbConfigs.length; i++) { + String type = xmldbConfigs[i].getAttribute("type"); + driver = xmldbConfigs[i].getAttribute("class"); + driverMap.put(type, driver); - Configuration[] xmldbConfigs = conf.getChildren("driver"); - - String type = null; - for (int i = 0; i < xmldbConfigs.length; i++) { - type = xmldbConfigs[i].getAttribute("type"); - driver = xmldbConfigs[i].getAttribute("class"); - driverMap.put(type, driver); - - if (getLogger().isDebugEnabled()) { - getLogger().debug("Initializing XML:DB connection, using driver " + driver); - } - - try { - - Class c = Class.forName(driver); - DatabaseManager.registerDatabase((Database)c.newInstance()); - - } catch (XMLDBException xde) { - - String error = "Unable to connect to the XMLDB database. Error " - + xde.errorCode + ": " + xde.getMessage(); - getLogger().debug(error, xde); - throw new ConfigurationException(error, xde); - - } catch (Exception e) { - - getLogger().error("There was a problem setting up the connection"); - getLogger().error("Make sure that your driver is available"); - throw new ConfigurationException("Problem setting up the connection to XML:DB: " - + e.getMessage(), e); - } + if (getLogger().isDebugEnabled()) { + getLogger().debug("Initializing XML:DB connection, using driver " + driver); } - } else { - throw new ConfigurationException("XMLDB configuration not found"); + try { + Class c = Class.forName(driver); + DatabaseManager.registerDatabase((Database)c.newInstance()); + } catch (XMLDBException xde) { + String error = "Unable to connect to the XMLDB database. Error " + + xde.errorCode + ": " + xde.getMessage(); + getLogger().debug(error, xde); + throw new ConfigurationException(error, xde); + } catch (Exception e) { + getLogger().error("There was a problem setting up the connection"); + getLogger().error("Make sure that your driver is available"); + throw new ConfigurationException("Problem setting up the connection to XML:DB: " + + e.getMessage(), e); + } } } 1.4 +151 -164 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/CastorTransformer.java Index: CastorTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/CastorTransformer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CastorTransformer.java 2 Aug 2002 09:21:00 -0000 1.3 +++ CastorTransformer.java 25 Jan 2003 03:02:11 -0000 1.4 @@ -2,6 +2,7 @@ import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.environment.Context; @@ -78,198 +79,184 @@ public CastorTransformer() { - /** - * Inner class eventhandler, forward the Castor SAX events - * to Cocoon 2 Events - */ - CastorEventAdapter = new HandlerBase(){ - public void startElement(String name, AttributeList attributes) throws SAXException - { - AttributesImpl a= new AttributesImpl(); - for(int i=0;i <attributes.getLength(); i++){ + /** + * Inner class eventhandler, forward the Castor SAX events + * to Cocoon 2 Events + */ + CastorEventAdapter = new HandlerBase(){ + public void startElement(String name, AttributeList attributes) throws SAXException + { + AttributesImpl a= new AttributesImpl(); + for(int i=0;i <attributes.getLength(); i++){ a.addAttribute("",attributes.getName(i),attributes.getName(i), - "",attributes.getValue(i)); - } + "",attributes.getValue(i)); + } - CastorTransformer.super.contentHandler.startElement("",name,name,a); - } - - public void characters(char[] chars, int offset, int length) throws SAXException - { - CastorTransformer.super.contentHandler.characters(chars, offset, length); - } + CastorTransformer.super.contentHandler.startElement("",name,name,a); + } - public void endElement(String name) throws SAXException - { + public void characters(char[] chars, int offset, int length) throws SAXException + { + CastorTransformer.super.contentHandler.characters(chars, offset, length); + } - CastorTransformer.super.contentHandler.endElement("", name,name); - } - }; - } + public void endElement(String name) throws SAXException + { + CastorTransformer.super.contentHandler.endElement("", name,name); + } + }; + } - public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params) throws org.apache.cocoon.ProcessingException, org.xml.sax.SAXException, java.io.IOException { - this.objectModel=objectModel; - this.resolver=resolver; - } - public void endElement(String uri, String name, String raw) throws org.xml.sax.SAXException { + public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params) throws org.apache.cocoon.ProcessingException, org.xml.sax.SAXException, java.io.IOException { + this.objectModel=objectModel; + this.resolver=resolver; + } - if(CASTOR_URI.equals(uri)){ + public void endElement(String uri, String name, String raw) throws org.xml.sax.SAXException { + if(CASTOR_URI.equals(uri)){ + in_castor_element= false; + return; + } - in_castor_element= false; - return; + super.endElement( uri, name, raw); + } + public void startElement(String uri, String name, String raw, Attributes attr) throws org.xml.sax.SAXException { + if(CASTOR_URI.equals(uri)){ + in_castor_element= true; + process(name,attr); + return; + } + super.startElement( uri, name, raw, attr); } - super.endElement( uri, name, raw); - } - public void startElement(String uri, String name, String raw, Attributes attr) throws org.xml.sax.SAXException { + public void characters(char[] ch, int start, int len) throws org.xml.sax.SAXException { + if(in_castor_element) + return; + super.characters(ch,start, len); + } - if(CASTOR_URI.equals(uri)){ - in_castor_element= true; + private void process(String command,Attributes attr){ - process(name,attr); - return; - } - super.startElement( uri, name, raw, attr); - } - public void characters(char[] ch, int start, int len) throws org.xml.sax.SAXException { - if(in_castor_element) - return; - super.characters(ch,start, len); - - } - - private void process(String command,Attributes attr){ - - if(command.equals(CMD_INSERT_BEAN)) { - String sourcemap = attr.getValue(ATTRIB_SCOPE); - String name = attr.getValue(ATTRIB_NAME); - String mapping = attr.getValue("mapping"); - Object toInsert; + if(command.equals(CMD_INSERT_BEAN)) { + String sourcemap = attr.getValue(ATTRIB_SCOPE); + String name = attr.getValue(ATTRIB_NAME); + String mapping = attr.getValue("mapping"); + Object toInsert; - Request request = ObjectModelHelper.getRequest(objectModel); + Request request = ObjectModelHelper.getRequest(objectModel); - if(name == null){ - getLogger().error("attribut to insert not set"); - } - /* - searcl all maps for the given bean - */ - else{ - if( sourcemap == null || VALUE_SITEMAP.equals(sourcemap)){ - //System.out.println("Searching bean " + name+ " in "+VALUE_SITEMAP); - toInsert=objectModel.get(name); - if(toInsert != null){ - insertBean(toInsert,mapping); - return; - } - } - if( sourcemap == null || VALUE_REQUEST.equals(sourcemap)){ - //System.out.println("Searching bean " + name+ " in "+ VALUE_REQUEST); - toInsert=request.getAttribute(name); - if(toInsert != null){ - insertBean(toInsert,mapping); - return; + if(name == null){ + getLogger().error("attribut to insert not set"); } - } - if(sourcemap == null || VALUE_SESSION.equals(sourcemap)){ - //System.out.println("Searching bean " + name+ " in "+VALUE_SESSION); - - Session session =request.getSession(false); - if(session != null){ - toInsert=session.getAttribute(name); - if(toInsert != null){ - insertBean(toInsert,mapping); - return; - } + /* + searcl all maps for the given bean + */ + else{ + if( sourcemap == null || VALUE_SITEMAP.equals(sourcemap)){ + //System.out.println("Searching bean " + name+ " in "+VALUE_SITEMAP); + toInsert=objectModel.get(name); + if(toInsert != null){ + insertBean(toInsert,mapping); + return; + } + } + if( sourcemap == null || VALUE_REQUEST.equals(sourcemap)){ + //System.out.println("Searching bean " + name+ " in "+ VALUE_REQUEST); + toInsert=request.getAttribute(name); + if(toInsert != null){ + insertBean(toInsert,mapping); + return; + } + } + if(sourcemap == null || VALUE_SESSION.equals(sourcemap)){ + //System.out.println("Searching bean " + name+ " in "+VALUE_SESSION); + + Session session =request.getSession(false); + if(session != null){ + toInsert=session.getAttribute(name); + if(toInsert != null){ + insertBean(toInsert,mapping); + return; + } + } + } + if(sourcemap == null || VALUE_CONTEXT.equals(sourcemap)){ + Context context = ObjectModelHelper.getContext(objectModel); + if(context != null){ + toInsert=context.getAttribute(name); + if(toInsert != null){ + insertBean(toInsert,mapping); + return; + } + } + } } - } - if(sourcemap == null || VALUE_CONTEXT.equals(sourcemap)){ - Context context = ObjectModelHelper.getContext(objectModel); - if(context != null){ - toInsert=context.getAttribute(name); - if(toInsert != null){ - insertBean(toInsert,mapping); - return; - } + getLogger().debug("Bean " +name + " could not be found"); + return; + } // end CMD_INSERT_BEAN + getLogger().error("Unknown command: " +command); + } + + private void insertBean(Object bean,String mappingpath){ + if(bean == null){ + getLogger().debug ("no bean found"); + return; + } + try{ + Mapping mapping; + if(mappingpath != null){ + mapping=mappingLoader(mappingpath); + } else { + mapping=mappingLoader(defaultmapping); } - } + + Marshaller marshaller= new Marshaller(CastorEventAdapter); + marshaller.setMapping(mapping); + marshaller.marshal(bean); + } catch(Exception e){ + e.printStackTrace(); } - getLogger().debug("Bean " +name + " could not be found"); - return; - } // end CMD_INSERT_BEAN - getLogger().error("Unknown command: " +command); - - } - - private void insertBean(Object bean,String mappingpath){ - if(bean == null){ - getLogger().debug ("no bean found"); - return; } - try{ - Mapping mapping; - if(mappingpath != null){ - mapping=mappingLoader(mappingpath); - } - else{ - mapping=mappingLoader(defaultmapping); - } + private Mapping mappingLoader(String path) throws MappingException,IOException{ + if(mappingCache == null){ + mappingCache= new HashMap(); + } + // cache already exsit + else{ + // and contain the mapping already + if(mappingCache.containsKey(path)){ + return (Mapping)mappingCache.get(path); + } + } + // mapping not found in cache or the cache is new + Mapping mapping = new Mapping(); + mapping.loadMapping(getFile(resolver,path)); + mappingCache.put(path,mapping); + return mapping; - Marshaller marshaller= new Marshaller(CastorEventAdapter); - marshaller.setMapping(mapping); - marshaller.marshal(bean); - } - catch(Exception e){ - e.printStackTrace(); } - } - private Mapping mappingLoader(String path) throws MappingException,IOException{ + public String getFile(SourceResolver sr, String FileName) { + try{ + String path = sr.resolveURI(FileName).getSystemId(); + if(path.startsWith(FILE_PREFIX)){ + path = path.substring(FILE_PREFIX.length()); + } + return path; - if(mappingCache == null){ - mappingCache= new HashMap(); - } - // cache already exsit - else{ - // and contain the mapping already - if(mappingCache.containsKey(path)){ - return (Mapping)mappingCache.get(path); - } + } + catch(Exception e){ + getLogger().error("could not read mapping file",e); + return null; + } } - // mapping not found in cache or the cache is new - Mapping mapping = new Mapping(); - mapping.loadMapping(getFile(resolver,path)); - mappingCache.put(path,mapping); - return mapping; - - } - - public String getFile(SourceResolver sr, String FileName) { - try{ - String path = sr.resolveURI(FileName).getSystemId(); - if(path.startsWith(FILE_PREFIX)){ - path = path.substring(FILE_PREFIX.length()); - } - return path; + public void configure(Configuration conf) throws ConfigurationException { + this.defaultmapping = conf.getChild(MAPPING_CONFIG).getValue(); } - catch(Exception e){ - getLogger().error("could not read mapping file",e); - return null; - } - } - public void configure(Configuration conf) throws org.apache.avalon.framework.configuration.ConfigurationException { - try{ - defaultmapping=conf.getChild(MAPPING_CONFIG).getValue(); - } - catch(Exception e){ - e.printStackTrace(); - getLogger().error("can't load default mapping",e); - } - } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]