xsddoc/src/net/sf/xframe/xsddoc Processor.java,1.24,1.25

Kurt Riede <[email protected]>
Newsgroups gmane.text.xml.xframe.xsddoc.devel
Message-ID <[email protected]>
Update of /cvsroot/xframe/xsddoc/src/net/sf/xframe/xsddoc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3012/src/net/sf/xframe/xsddoc

Modified Files:
	Processor.java 
Log Message:
support cameleon schema, process nested elements in russion doll components

Index: Processor.java
===================================================================
RCS file: /cvsroot/xframe/xsddoc/src/net/sf/xframe/xsddoc/Processor.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** Processor.java	20 Aug 2004 14:44:00 -0000	1.24
--- Processor.java	30 Aug 2004 07:16:10 -0000	1.25
***************
*** 69,77 ****
      ////////////////////////////////////////////////
  
      /** Folder name for components that do not belong to a namespace. */
!     private static final String NO_NAMESPACE = "noNamespace";
  
      /** protocol prefix for resource files. */
!     private static final String RESOURCE_PROTOCOL = "resource:";
  
      /** file extension of HTML files. */
--- 69,83 ----
      ////////////////////////////////////////////////
  
+     /** Namespace-URI of namespace of W3C-XML-Namespace. */
+     public static final String HTTP_WWW_W3_ORG_2000_XMLNS = "http://www.w3.org/2000/xmlns/";
+ 
+     /** Attribute name: targetNamespace. */
+     public static final String TARGETNAMESPACE = "targetNamespace";
+ 
      /** Folder name for components that do not belong to a namespace. */
!     public static final String NO_NAMESPACE = "noNamespace";
  
      /** protocol prefix for resource files. */
!     public static final String RESOURCE_PROTOCOL = "resource:";
  
      /** file extension of HTML files. */
***************
*** 161,165 ****
  
      /** if verbose mode or not. */
!     private boolean verbose = false;
  
      /** if debug mode or not. */
--- 167,171 ----
  
      /** if verbose mode or not. */
!     private boolean verbose = true;
  
      /** if debug mode or not. */
***************
*** 578,584 ****
              processInclude(schema, component, schemaLocation);
          } else {
!             final String name = DomUtil.getAttributeValue(component, "name");
              if (verbose) {
!                 final String targetNamespace = DomUtil.getAttributeValue(schema.getDocumentElement(), "targetNamespace");
                  System.out.println("process " + "{" + targetNamespace + "}" + name + " from file " + schemaLocation);
              }
--- 584,596 ----
              processInclude(schema, component, schemaLocation);
          } else {
!             final String localName = DomUtil.getAttributeValue(component, "name");
!             final String name;
!             if (parentName == null || "".equals(parentName)) {
!                 name = localName;
!             } else {
!                 name = parentName + "." + localName;
!             }
              if (verbose) {
!                 final String targetNamespace = DomUtil.getAttributeValue(schema.getDocumentElement(), TARGETNAMESPACE);
                  System.out.println("process " + "{" + targetNamespace + "}" + name + " from file " + schemaLocation);
              }
***************
*** 589,592 ****
--- 601,605 ----
                  new File(subfolder + FILE_SEP + componentType).mkdir();
                  final Source source = getSource(schema, getSystemId(schemaLocation));
+                 ((Element) component).setAttribute("xsddocid", "a");
                  if (xml) {
                      transform(source, tComponent, component,
***************
*** 598,602 ****
                          subfolder + FILE_SEP + componentType + FILE_SEP + name + getExtension());
                  }
!                 searchLocalElementDeclarations(schema, schemaLocation, component, parentName);
              }
          }
--- 611,618 ----
                          subfolder + FILE_SEP + componentType + FILE_SEP + name + getExtension());
                  }
!                 ((Element) component).removeAttribute("xsddocid");
!                 if ("element".equals(componentType) || "complexType".equals(componentType)) {
!                     searchLocalElementDeclarations(schema, schemaLocation, component, name);
!                 }
              }
          }
***************
*** 629,636 ****
              if (nestedComponent.getNodeType() == Node.ELEMENT_NODE) {
                  if ("element".equals(nestedComponent.getLocalName())) {
!                     final String name = DomUtil.getAttributeValue(component, "name");
!                     if (name != null && !"".equals(name)) {
!                         processComponent(schema, schemaLocation, nestedComponent, parentName + "." + name);
                      }
                  }
              }
--- 645,655 ----
              if (nestedComponent.getNodeType() == Node.ELEMENT_NODE) {
                  if ("element".equals(nestedComponent.getLocalName())) {
!                     final String ref = DomUtil.getAttributeValue(nestedComponent, "ref");
!                     final String type = DomUtil.getAttributeValue(nestedComponent, "type");
!                     if (ref == null && type == null) {
!                         processComponent(schema, schemaLocation, nestedComponent, parentName);
                      }
+                 } else {
+                     searchLocalElementDeclarations(schema, schemaLocation, nestedComponent, parentName);
                  }
              }
***************
*** 640,643 ****
--- 659,665 ----
      /**
       * Process include element within the current schema.
+      * <p>If the included schema doesn't have a target namespace, it is
+      * processed as a cameleon schema, meaning the target namespace of the
+      * including schema is temporary inherited to the included schema.</p>
       *
       * @param schema root Node of DOM tree of current schema
***************
*** 661,669 ****
              return;
          }
!         final String includedSchemaLocation = getLocation(schemaLocation, rawSchemaLocation);
          if (debug) {
              System.out.println("process included schema " + includedSchemaLocation);
          }
          final Document includedSchema = getDocument(getSystemId(includedSchemaLocation));
          processComponents(includedSchema, includedSchemaLocation);
          final NodeList components = component.getChildNodes();
--- 683,696 ----
              return;
          }
!         final String includedSchemaLocation = FileUtil.getLocation(schemaLocation, rawSchemaLocation);
          if (debug) {
              System.out.println("process included schema " + includedSchemaLocation);
          }
          final Document includedSchema = getDocument(getSystemId(includedSchemaLocation));
+         boolean isCameleon = false;
+         if ("".equals(getTargetNamespace(includedSchema))) {
+             isCameleon = true;
+             setTargetNamespace(includedSchema, getTargetNamespace(schema));
+         }
          processComponents(includedSchema, includedSchemaLocation);
          final NodeList components = component.getChildNodes();
***************
*** 674,678 ****
              }
          }
! 
      }
  
--- 701,707 ----
              }
          }
!         if (isCameleon) {
!             setTargetNamespace(includedSchema, "");
!         }
      }
  
***************
*** 699,703 ****
              return;
          }
!         final String importedSchemaLocation = getLocation(schemaLocation, rawSchemaLocation);
          if (debug) {
              System.out.println("process imported schema " + importedSchemaLocation);
--- 728,732 ----
              return;
          }
!         final String importedSchemaLocation = FileUtil.getLocation(schemaLocation, rawSchemaLocation);
          if (debug) {
              System.out.println("process imported schema " + importedSchemaLocation);
***************
*** 888,896 ****
       */
      private String getTargetNamespace(final Document schema) {
!         final String targetNameSpace = DomUtil.getAttributeValue(schema.getDocumentElement(), "targetNamespace");
          return targetNameSpace == null ? "" : targetNameSpace;
      }
  
      /**
       * Converts an URI to a folder name.
       *
--- 917,942 ----
       */
      private String getTargetNamespace(final Document schema) {
!         final String targetNameSpace = DomUtil.getAttributeValue(schema.getDocumentElement(), TARGETNAMESPACE);
          return targetNameSpace == null ? "" : targetNameSpace;
      }
  
      /**
+      * Sets or overwrites the targetNamespace in a schema.
+      * <p>Setting the target namespace of schema means
+      * <ul>
+      * <li>settings the attribute <code>targetNamespace</code> to the value
+      * of the target namespace and</li>
+      * <li>setting the default namespace to the target namespace</li>
+      * </ul>
+      * @param schema the schema modify
+      * @param namespace identifier
+      */
+     private void setTargetNamespace(final Document schema, final String namespace) {
+         final Element schemaElement = (Element) DomUtil.getFirstElementChild(schema);
+         schemaElement.setAttribute(TARGETNAMESPACE, namespace == null ? "noNamespace" : namespace);
+         schemaElement.setAttributeNS(HTTP_WWW_W3_ORG_2000_XMLNS, "xmlns", namespace);
+     }
+ 
+     /**
       * Converts an URI to a folder name.
       *
***************
*** 906,929 ****
  
      /**
-      * Returns the location of a file relative to a base file.
-      *
-      * @param baseFile the base file
-      * @param file the file to be resolved
-      * @return resolved location
-      */
-     private String getLocation(final String baseFile, final String file) {
-         if (baseFile == null || file.indexOf(':') > 0) {
-             return file;
-         } else {
-             final String parent = new File(baseFile).getParent();
-             if (parent == null) {
-                 return file;
-             } else {
-                 return parent + FILE_SEP + file;
-             }
-         }
-     }
- 
-     /**
       * Returns an InputStream to a named resource.
       *
--- 952,955 ----



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.