File Source: Service.java

         /* 
    P/P   *  Method: org.apache.roller.weblogger.webservices.adminprotocol.sdk.Service$Workspace__static_init
          */
     1  /*
     2  * Licensed to the Apache Software Foundation (ASF) under one or more
     3  *  contributor license agreements.  The ASF licenses this file to You
     4  * under the Apache License, Version 2.0 (the "License"); you may not
     5  * use this file except in compliance with the License.
     6  * You may obtain a copy of the License at
     7  *
     8  *     http://www.apache.org/licenses/LICENSE-2.0
     9  *
    10  * Unless required by applicable law or agreed to in writing, software
    11  * distributed under the License is distributed on an "AS IS" BASIS,
    12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  * See the License for the specific language governing permissions and
    14  * limitations under the License.  For additional information regarding
    15  * copyright in this work, please see the NOTICE file in the top level
    16  * directory of this distribution.
    17  */
    18  /*
    19   * AtomAdminService.java
    20   *
    21   * Created on January 17, 2006, 12:44 PM
    22   */
    23  package org.apache.roller.weblogger.webservices.adminprotocol.sdk;
    24  
    25  import java.io.IOException;
    26  import java.io.InputStream;
    27  import java.util.ArrayList;
    28  import java.util.Iterator;
    29  import java.util.List;
    30  import org.apache.roller.weblogger.webservices.adminprotocol.sdk.EntrySet.Types;
    31  
    32  import org.jdom.Document;
    33  import org.jdom.Element;
    34  import org.jdom.JDOMException;
    35  import org.jdom.input.SAXBuilder;
    36  
    37  /**
    38   * This class describes an RAP service (introspection document).
    39   * A Service is a set of workspaces, which is a set of
    40   * collections.
    41   *
    42   * @author jtb
    43   */
    44  
    45  public class Service extends EntrySet {
    46      
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.webservices.adminprotocol.sdk.Service(String)
              * 
              *  Postconditions:
              *    this.entries == null
              *    this.href == href
              *    init'ed(this.href)
              */
    47      public Service(String href) {
    48          setHref(href);
    49      }
    50      
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.webservices.adminprotocol.sdk.Service(Document)
              * 
              *  Preconditions:
              *    d != null
              * 
              *  Postconditions:
              *    init'ed(this.entries)
              *    init'ed(this.href)
              */
    51      public Service(Document d) throws UnexpectedRootElementException {
    52          populate(d);
    53      }
    54      
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.webservices.adminprotocol.sdk.Service(InputStream)
              * 
              *  Presumptions:
              *    org.jdom.input.SAXBuilder:build(...)@57 != null
              * 
              *  Postconditions:
              *    init'ed(this.entries)
              *    init'ed(this.href)
              */
    55      public Service(InputStream stream) throws JDOMException, IOException, UnexpectedRootElementException {               
    56          SAXBuilder sb = new SAXBuilder();
    57          Document d = sb.build(stream);
    58          populate(d);        
    59      }    
    60  
    61      public String getType() {
                 /* 
    P/P           *  Method: String getType()
                  * 
                  *  Postconditions:
                  *    return_value == &"service"
                  */
    62          return Types.SERVICE;
    63      }
    64      
    65      public Document toDocument() {
                 /* 
    P/P           *  Method: Document toDocument()
                  * 
                  *  Preconditions:
                  *    this.entries != null
                  * 
                  *  Presumptions:
                  *    getEntries(...).length@70 <= 232-1
                  *    getEntries(...).length@71 >= 1
                  *    getEntries(...).length@70 <= getEntries(...).length@71
                  *    java.util.List:toArray(...)@72 != null
                  *    toDocument(...)@72 != null
                  * 
                  *  Postconditions:
                  *    return_value == &new Document(toDocument#1)
                  *    new Document(toDocument#1) num objects == 1
                  */
    66          Document doc = new Document();
    67          Element root = new Element(Types.SERVICE, NAMESPACE);
    68          doc.setRootElement(root);
    69          
    70          for (int i = 0; i < getEntries().length; i++) {
    71              Entry entry = getEntries()[i];
+   72              root.addContent(entry.toDocument().detachRootElement());
    73          }
    74          
    75          return doc;
    76      }
    77  
    78      public void populate(Document doc) {
                 /* 
    P/P           *  Method: void populate(Document)
                  * 
                  *  Preconditions:
                  *    doc != null
                  * 
                  *  Presumptions:
                  *    java.util.Iterator:next(...)@84 != null
                  *    org.jdom.Document:getRootElement(...)@79 != null
                  *    org.jdom.Element:getChildren(...)@81 != null
                  * 
                  *  Postconditions:
                  *    init'ed(this.entries)
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@83: {0}, {1}
                  */
    79          Element root = doc.getRootElement();
    80          List workspaces = new ArrayList();
    81          List spaces = root.getChildren("workspace", NAMESPACE);
    82          Iterator iter = spaces.iterator();
    83          while (iter.hasNext()) {
    84              Element e = (Element) iter.next();
    85              Workspace ws = new Workspace();
    86              ws.populate(e);
    87              workspaces.add(ws);
    88          }
    89          setEntries((Entry[])workspaces.toArray(new Workspace[0]));
    90      }
    91              
    92      /** This class describes a service workspace. */    
    93      public static class Workspace extends EntrySet {   
    94          
    95          private static interface Attributes {
    96              public static final String TITLE = "title";
    97          }
    98          
    99          private String title = null;
   100          
                 /* 
    P/P           *  Method: void org.apache.roller.weblogger.webservices.adminprotocol.sdk.Service$Workspace()
                  * 
                  *  Postconditions:
                  *    this.entries == null
                  *    this.href == null
                  *    this.title == null
                  */
   101          public Workspace() {
   102          }
   103          
   104          public String getType() {
                     /* 
    P/P               *  Method: String getType()
                      * 
                      *  Postconditions:
                      *    return_value == &"workspace"
                      */
   105              return Types.WORKSPACE;
   106          }
   107          
   108          public String getTitle() {
                     /* 
    P/P               *  Method: String getTitle()
                      * 
                      *  Preconditions:
                      *    init'ed(this.title)
                      * 
                      *  Postconditions:
                      *    return_value == this.title
                      *    init'ed(return_value)
                      */
   109              return title;
   110          }
   111          
   112          public void setTitle(String title) {
                     /* 
    P/P               *  Method: void setTitle(String)
                      * 
                      *  Postconditions:
                      *    this.title == title
                      *    init'ed(this.title)
                      */
   113              this.title = title;
   114          }
   115          
   116          
   117          public Document toDocument() {
                     /* 
    P/P               *  Method: Document toDocument()
                      * 
                      *  Preconditions:
                      *    this.entries != null
                      *    init'ed(this.title)
                      * 
                      *  Presumptions:
                      *    getEntries(...).length@123 <= 232-1
                      *    getEntries(...).length@124 >= 1
                      *    getEntries(...).length@123 <= getEntries(...).length@124
                      *    java.util.List:toArray(...)@72 != null
                      *    toDocument(...)@125 != null
                      * 
                      *  Postconditions:
                      *    return_value == &new Document(toDocument#1)
                      *    new Document(toDocument#1) num objects == 1
                      */
   118              Document doc = new Document();
   119              Element element = new Element(EntrySet.Types.WORKSPACE, NAMESPACE);
   120              doc.setRootElement(element);
   121              
   122              element.setAttribute(Attributes.TITLE, getTitle());
   123              for (int i = 0; i < getEntries().length; i++) {
   124                  Entry entry = getEntries()[i];
+  125                  element.addContent(entry.toDocument().detachRootElement());
   126              }
   127              
   128              return doc;
   129          }
   130          
   131          public void populate(Element elem) {
                     /* 
    P/P               *  Method: void populate(Element)
                      * 
                      *  Preconditions:
                      *    elem != null
                      * 
                      *  Presumptions:
                      *    java.util.Iterator:next(...)@137 != null
                      *    org.jdom.Element:getChildren(...)@134 != null
                      * 
                      *  Postconditions:
                      *    init'ed(this.entries)
                      *    init'ed(this.title)
                      * 
                      *  Test Vectors:
                      *    java.util.Iterator:hasNext(...)@136: {0}, {1}
                      */
   132              setTitle(elem.getAttributeValue(Attributes.TITLE)); //, NAMESPACE));
   133              List collections = new ArrayList();
   134              List spaces = elem.getChildren("collection", NAMESPACE);
   135              Iterator iter = spaces.iterator();
   136              while (iter.hasNext()) {
   137                  Element e = (Element) iter.next();
   138                  Collection col = new Collection();
   139                  col.populate(e);
   140                  collections.add(col);
   141              }
   142              Workspace.this.setEntries((Entry[])collections.toArray(new Collection[0]));
   143          }
   144  
   145  
   146          /** This class describes a workspace collection. */
   147          public static class Collection extends Entry {
   148              
   149              private static interface Tags {
   150                  public static final String MEMBER_TYPE = "member-type";
   151              }
   152              
   153              private static interface Attributes {
   154                  public static final String TITLE = "title";
   155              }
   156              
   157              private String title;
   158              private String memberType;
   159              
                     /* 
    P/P               *  Method: void org.apache.roller.weblogger.webservices.adminprotocol.sdk.Service$Workspace$Collection()
                      * 
                      *  Postconditions:
                      *    this.href == null
                      */
   160              public Collection() {
   161                  // nothing
   162              }
   163              
   164              public String getType() {
                         /* 
    P/P                   *  Method: String getType()
                          * 
                          *  Postconditions:
                          *    return_value == &"collection"
                          */
   165                  return Types.COLLECTION;
   166              }
   167              
   168              public String getTitle() {
                         /* 
    P/P                   *  Method: String getTitle()
                          * 
                          *  Preconditions:
                          *    init'ed(this.title)
                          * 
                          *  Postconditions:
                          *    return_value == this.title
                          *    init'ed(return_value)
                          */
   169                  return title;
   170              }
   171              
   172              public void setTitle(String title) {
                         /* 
    P/P                   *  Method: void setTitle(String)
                          * 
                          *  Postconditions:
                          *    this.title == title
                          *    init'ed(this.title)
                          */
   173                  this.title = title;
   174              }
   175              
   176              
   177              public Document toDocument() {
                         /* 
    P/P                   *  Method: Document toDocument()
                          * 
                          *  Preconditions:
                          *    init'ed(this.href)
                          *    init'ed(this.memberType)
                          *    init'ed(this.title)
                          * 
                          *  Postconditions:
                          *    return_value == &new Document(toDocument#1)
                          *    new Document(toDocument#1) num objects == 1
                          */
   178                  Document doc = new Document();
   179                  Element element = new Element(Types.COLLECTION, NAMESPACE);
   180                  doc.setRootElement(element);
   181                  
   182                  element.setAttribute(Attributes.TITLE, getTitle());
   183                  element.setAttribute(Entry.Attributes.HREF, getHref());
   184                  
   185                  Element memberType = new Element(Tags.MEMBER_TYPE, NAMESPACE);
   186                  memberType.setText(getMemberType());
   187                  element.addContent(memberType);
   188                  
   189                  return doc;
   190              }
   191              
   192              
   193              public void populate(Element elem) {
                         /* 
    P/P                   *  Method: void populate(Element)
                          * 
                          *  Preconditions:
                          *    elem != null
                          * 
                          *  Presumptions:
                          *    org.jdom.Element:getChild(...)@196 != null
                          * 
                          *  Postconditions:
                          *    init'ed(this.href)
                          *    init'ed(this.memberType)
                          *    init'ed(this.title)
                          */
   194                  setTitle(elem.getAttributeValue(Attributes.TITLE)); //, NAMESPACE));
   195                  setHref(elem.getAttributeValue(Entry.Attributes.HREF)); //, NAMESPACE));
   196                  Element typeElem = elem.getChild(Tags.MEMBER_TYPE, NAMESPACE);
   197                  setMemberType(typeElem.getText());
   198              }
   199              
   200              public String getMemberType() {
                         /* 
    P/P                   *  Method: String getMemberType()
                          * 
                          *  Preconditions:
                          *    init'ed(this.memberType)
                          * 
                          *  Postconditions:
                          *    return_value == this.memberType
                          *    init'ed(return_value)
                          */
   201                  return memberType;
   202              }
   203              
   204              public void setMemberType(String memberType) {
                         /* 
    P/P                   *  Method: void setMemberType(String)
                          * 
                          *  Postconditions:
                          *    this.memberType == memberType
                          *    init'ed(this.memberType)
                          */
   205                  this.memberType = memberType;
   206              }
   207              
   208          }
   209          
   210      }
   211      
   212  }








SofCheck Inspector Build Version : 2.18479
Service.java 2009-Jan-02 14:24:46
Service.class 2009-Sep-04 03:12:46
Service$Workspace.class 2009-Sep-04 03:12:46
Service$Workspace$Attributes.class 2009-Sep-04 03:12:46
Service$Workspace$Collection.class 2009-Sep-04 03:12:46
Service$Workspace$Collection$Attributes.class 2009-Sep-04 03:12:46
Service$Workspace$Collection$Tags.class 2009-Sep-04 03:12:46