You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-dev@ws.apache.org by ip...@apache.org on 2004/12/20 21:39:14 UTC

svn commit: r122876 - /incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/AbstractJavaSysPropsResource.java /incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/JavaSysPropsResource.java

Author: ips
Date: Mon Dec 20 12:39:11 2004
New Revision: 122876

URL: http://svn.apache.org/viewcvs?view=rev&rev=122876
Log:
split out into two classes

Added:
   incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/AbstractJavaSysPropsResource.java
Modified:
   incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/JavaSysPropsResource.java

Added: incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/AbstractJavaSysPropsResource.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/AbstractJavaSysPropsResource.java?view=auto&rev=122876
==============================================================================
--- (empty file)
+++ incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/AbstractJavaSysPropsResource.java	Mon Dec 20 12:39:11 2004
@@ -0,0 +1,137 @@
+/*=============================================================================*
+ *  Copyright 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 example.sysprops;
+
+import org.apache.ws.resource.PropertiesResource;
+import org.apache.ws.resource.Resource;
+import org.apache.ws.resource.lifetime.ResourceLifetime1_2Constants;
+import org.apache.ws.resource.properties.ResourcePropertySet;
+import org.apache.ws.resource.properties.XmlBeansResourcePropertyUtils;
+import org.apache.ws.resource.properties.impl.XmlBeansResourceProperty;
+import org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySet;
+
+import java.util.Calendar;
+
+/**
+ * An abstract filesystem WS-Resource.
+ * <p/>
+ * NOTE: This class is generated and is NOT meant to be modified.
+ *
+ * @author Ian P. Springer
+ * @author Sal Campana
+ */
+public abstract class AbstractJavaSysPropsResource implements Resource, PropertiesResource
+{
+    /**
+     * The resource ID of the instance.
+     */
+    protected String m_id;
+
+    /**
+     * The ResourceProperty Set containing the resource props.
+     */
+    protected ResourcePropertySet m_propSet;
+
+    /**
+     * Returns the current time from the prop set.
+     *
+     * @return Calendar
+     */
+    public Calendar getCurrentTime()
+    {
+        return XmlBeansResourcePropertyUtils.getDateTimeProperty( (XmlBeansResourceProperty) m_propSet.get( ResourceLifetime1_2Constants.PROP_QNAME_CURRENT_TIME ) );
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @param id DOCUMENT_ME
+     */
+    public void setID( Object id )
+    {
+        if ( m_id != null )
+        {
+            throw new IllegalStateException( "This resource's ID has already been set." );
+        }
+
+        try
+        {
+            m_id = (String) id;
+        }
+        catch ( ClassCastException cce )
+        {
+            throw new IllegalArgumentException( "Specified ID is not a String." );
+        }
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public Object getID()
+    {
+        return m_id;
+    }
+
+    /**
+     * @see org.apache.ws.resource.PropertiesResource#setResourcePropertySet(org.apache.ws.resource.properties.ResourcePropertySet)
+     */
+    public void setResourcePropertySet( ResourcePropertySet propSet )
+    {
+        m_propSet = propSet;
+    }
+
+    /**
+     * @see org.apache.ws.resource.PropertiesResource#getResourcePropertySet()
+     */
+    public ResourcePropertySet getResourcePropertySet()
+    {
+        return m_propSet;
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @param time DOCUMENT_ME
+     */
+    public void setTerminationTime( Calendar time )
+    {
+        XmlBeansResourcePropertyUtils.setDateTimeProperty( (XmlBeansResourceProperty) getResourcePropertySet().get( ResourceLifetime1_2Constants.PROP_QNAME_TERMINATION_TIME ),
+                time );
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public Calendar getTerminationTime()
+    {
+        return XmlBeansResourcePropertyUtils.getDateTimeProperty( (XmlBeansResourceProperty) m_propSet.get( ResourceLifetime1_2Constants.PROP_QNAME_TERMINATION_TIME ) );
+    }
+
+    public void destroy()
+    {
+        return;
+    }
+
+    public void init()
+    {
+        JavaSystemPropertiesDocument propsDoc = JavaSystemPropertiesDocument.Factory.newInstance();
+        m_propSet = new XmlBeansResourcePropertySet( propsDoc );
+    }
+}

Modified: incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/JavaSysPropsResource.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/JavaSysPropsResource.java?view=diff&rev=122876&p1=incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/JavaSysPropsResource.java&r1=122875&p2=incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/JavaSysPropsResource.java&r2=122876
==============================================================================
--- incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/JavaSysPropsResource.java	(original)
+++ incubator/apollo/trunk/src/site/content/tutorial/src/example/sysprops/JavaSysPropsResource.java	Mon Dec 20 12:39:11 2004
@@ -1,11 +1,7 @@
 package example.sysprops;
 
-import org.apache.ws.resource.PropertiesResource;
-import org.apache.ws.resource.Resource;
-import org.apache.ws.resource.example.sysprops.JavaSystemPropertiesDocument;
 import org.apache.ws.resource.properties.ResourceProperty;
 import org.apache.ws.resource.properties.ResourcePropertyMetaData;
-import org.apache.ws.resource.properties.ResourcePropertySet;
 import org.apache.ws.resource.properties.impl.AnyResourcePropertyMetaData;
 import org.apache.ws.resource.properties.impl.XmlBeansResourceProperty;
 import org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySet;
@@ -16,83 +12,42 @@
 import java.util.Iterator;
 import java.util.Properties;
 
-
 /**
  * @author Sal Campana
  */
-public class JavaSysPropsResource implements Resource,
-                                             PropertiesResource
+public class JavaSysPropsResource extends AbstractJavaSysPropsResource
 {
-    /**
-     * The resource ID of the instance.
-     */
-    Object m_id;
-
-    /**
-     * The ResourceProperty Set containing the resource props.
-     */
-    ResourcePropertySet m_propSet;
-    private static final String ELEM_PROPERTY = "property";
-
-    public void setID(Object id)
-    {
-        m_id = id;
-    }
 
-    public Object getID()
-    {
-        return m_id;
-    }
-
-    public void destroy()
-    {
-        m_propSet = null;
-        m_id = null;
-    }
+    private static final String ELEM_NAME_PROPERTY = "property";
 
     public void init()
     {
-        JavaSystemPropertiesDocument propDoc = JavaSystemPropertiesDocument.Factory.newInstance();
-        m_propSet = new XmlBeansResourcePropertySet(propDoc);
+        super.init();
         //create a resource metadata and resource property
-        ResourcePropertyMetaData propMetaData = new AnyResourcePropertyMetaData(new QName(JavaSysPropsService.TARGET_NSURI, ELEM_PROPERTY));
-        ResourceProperty prop = new XmlBeansResourceProperty(propMetaData, (XmlBeansResourcePropertySet) m_propSet);
+        ResourcePropertyMetaData propMetaData = new AnyResourcePropertyMetaData( new QName( JavaSysPropsService.TARGET_NSURI, ELEM_NAME_PROPERTY ) );
+        ResourceProperty prop = new XmlBeansResourceProperty( propMetaData, (XmlBeansResourcePropertySet) m_propSet );
         //add the property to the prop set
-        m_propSet.add(prop);
+        m_propSet.add( prop );
 
         //get the current sys properties
-        Properties properties = System.getProperties();
-        Iterator iterator = properties.keySet().iterator();
+        Properties sysProps = System.getProperties();
+        Iterator iterator = sysProps.keySet().iterator();
         //iterate the sysprops and add to property set
-        while (iterator.hasNext())
+        while ( iterator.hasNext() )
         {
-            XmlObject xmlObject = null;
-            //get each key/value pair
-            String key = (String) iterator.next();
-            String value = properties.getProperty(key);
+            String sysPropKey = (String) iterator.next();
+            String sysPropValue = sysProps.getProperty( sysPropKey );
             try
             {
                 //build an arbitrary XmlObject out of the sysprop data
-                xmlObject = XmlObject.Factory.parse("<" + JavaSysPropsService.TARGET_NSPREFIX + ":" + ELEM_PROPERTY + " name=\"" + key + "\" value=\"" + value + "\" xmlns:" + JavaSysPropsService.TARGET_NSPREFIX + "=\"" + JavaSysPropsService.TARGET_NSURI + "\"/>");
+                XmlObject propElem = XmlObject.Factory.parse( "<" + JavaSysPropsService.TARGET_NSPREFIX + ":" + ELEM_NAME_PROPERTY + " name=\"" + sysPropKey + "\" value=\"" + sysPropValue + "\" xmlns:" + JavaSysPropsService.TARGET_NSPREFIX + "=\"" + JavaSysPropsService.TARGET_NSURI + "\"/>" );
+                prop.add( propElem );
             }
-            catch (XmlException e)
+            catch ( XmlException e )
             {
                 e.printStackTrace();
             }
-
-            //add the XmlObject to the property
-            prop.add(xmlObject);
         }
-
-    }
-
-    public ResourcePropertySet getResourcePropertySet()
-    {
-        return m_propSet;
     }
 
-    public void setResourcePropertySet(ResourcePropertySet propSet)
-    {
-        m_propSet = propSet;
-    }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: apollo-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: apollo-dev-help@ws.apache.org