You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrp4j-dev@portals.apache.org by dl...@apache.org on 2005/08/29 00:53:02 UTC
cvs commit: ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver ConsumerConfiguredPortletList.java ConsumerPortletRegistrationList.java PersistentDataObjectImpl.java PersistentHandlerImpl.java PersistentInformationImpl.java PortletDescriptionList.java PortletList.java ProducerList.java RegistrationList.java ServerPersistentFactoryImpl.java ServerPersistentInformationProviderImpl.java ServiceDescriptionList.java UserList.java
dlouzan 2005/08/28 15:53:02
Added: sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver
ConsumerConfiguredPortletList.java
ConsumerPortletRegistrationList.java
PersistentDataObjectImpl.java
PersistentHandlerImpl.java
PersistentInformationImpl.java
PortletDescriptionList.java PortletList.java
ProducerList.java RegistrationList.java
ServerPersistentFactoryImpl.java
ServerPersistentInformationProviderImpl.java
ServiceDescriptionList.java UserList.java
Log:
Initial commit.
Revision Changes Path
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/ConsumerConfiguredPortletList.java
Index: ConsumerConfiguredPortletList.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import java.io.FileReader;
import java.io.FileWriter;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.apache.wsrp4j.commons.producer.provider.driver.ConsumerConfiguredPortletImpl;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
/**
* This class collects ConsumerConfiguredPortlets and implements the
* marshal / unmarshal methods for CASTOR XML file support. Detailed
* information on persistent organizational data has to be requested
* with this class from the corresponding PersistentInformationProvider.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
* @see PersistentHandler
* @see ProducerPersistentInformationProvider
*
* @version $Id: ConsumerConfiguredPortletList.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class ConsumerConfiguredPortletList extends PersistentDataObjectImpl {
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Default Constructor
*/
public ConsumerConfiguredPortletList() {
}
/**
* Constructs a ConsumerConfiguredPortlet object from a CASTOR persistent
* XML file.
*
* @param fileReader to the input data file
*
* @param unmarshaller optional, part of the CASTOR package. In case of
* a null value as input parameter, the static methods
* of the CASTOR unmarshaller are used.
*
* @throws WSRPException
*/
public void unMarshalFile(FileReader fileReader, Unmarshaller unmarshaller)
throws WSRPException {
String MN = "unMarshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (unmarshaller == null) {
addObject(Unmarshaller.unmarshal(
ConsumerConfiguredPortletImpl.class, fileReader));
} else {
addObject(unmarshaller.unmarshal(fileReader));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.UNMARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Writes a ConsumerConfiguredPortlet, which must be the first element
* in the PersistentDataObject map, to a persistent XML file. In case
* of a null value as input parameter, the static methods of the CASTOR
* Marshaller are used.
*
* @param fileWriter to the output XML file
* @param marshaller, optional
*
* @throws WSRPException
*/
public void marshalFile(FileWriter fileWriter, Marshaller marshaller)
throws WSRPException {
String MN = "marshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (marshaller == null) {
Marshaller.marshal(_objects.get(0), fileWriter);
} else {
marshaller.marshal(_objects.get(0));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.MARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/ConsumerPortletRegistrationList.java
Index: ConsumerPortletRegistrationList.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import java.io.FileReader;
import java.io.FileWriter;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.apache.wsrp4j.commons.producer.provider.driver.
ConsumerPortletRegistrationImpl;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
/**
* This class collects ConsumerPortletRegistrations and implements the
* marshal / unmarshal methods for CASTOR XML file support. Detailed
* information on persistent organizational data has to be requested
* with this class from the corresponding PersistentInformationProvider.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
*
* @version $Id: ConsumerPortletRegistrationList.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class ConsumerPortletRegistrationList extends PersistentDataObjectImpl {
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Default Constructor
*/
public ConsumerPortletRegistrationList() {
}
/**
* Constructs a ConsumerPortletRegistration object from a CASTOR persistent
* XML file.
*
* @param fileReader to the input data file
*
* @param unmarshaller optional, part of the CASTOR package. In case of
* a null value as input parameter, the static methods
* of the CASTOR unmarshaller are used.
*
* @throws WSRPException
*/
public void unMarshalFile(FileReader fileReader, Unmarshaller unmarshaller)
throws WSRPException {
String MN = "unMarshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (unmarshaller == null) {
addObject(Unmarshaller.unmarshal(
ConsumerPortletRegistrationImpl.class, fileReader));
} else {
addObject(unmarshaller.unmarshal(fileReader));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.UNMARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
}
/**
* Writes a ConsumerPortletRegistration, which must be the first element
* in the PersistentDataObject map, to a persistent XML file. In case
* of a null value as input parameter, the static methods of the CASTOR
* Marshaller are used.
*
* @param fileWriter to the output XML file
* @param marshaller, optional
*
* @throws WSRPException
*/
public void marshalFile(FileWriter fileWriter, Marshaller marshaller)
throws WSRPException {
String MN = "marshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (marshaller == null) {
Marshaller.marshal(_objects.get(0), fileWriter);
} else {
marshaller.marshal(_objects.get(0));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.MARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/PersistentDataObjectImpl.java
Index: PersistentDataObjectImpl.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import org.apache.wsrp4j.commons.persistence.PersistentInformation;
import org.apache.wsrp4j.persistence.xml.PersistentDataObjectXML;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
/**
* This class is the abstract implementation of the class
* PersistentDataObjectXML.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
* @version $Id: PersistentDataObjectImpl.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public abstract class PersistentDataObjectImpl
implements PersistentDataObjectXML {
// the persistent information
private PersistentInformation _persistentInfo = null;
// list of objects to be stored or as result of the restore
protected ArrayList _objects = new ArrayList();
// the last element added to the list
protected Object _lastElement = null;
/**
* Set the persistent information object to this data object.
*
* @param persistentInfo
*/
public void setPersistentInformation(PersistentInformation persistentInfo) {
_persistentInfo = persistentInfo;
}
/**
* Returns the persistent information object, contained in this data object.
*
* @return persistentInformation
*/
public PersistentInformation getPersistentInformation() {
return _persistentInfo;
}
/**
* Clears the object array
*/
public void clear() {
_objects.clear();
}
/**
* Returns the list of objects as an iterator.
*
* @return iterator of objects
*/
public Iterator getObjects() {
return _objects.iterator();
}
/**
* Add an object to the internal list.
*
* @param object to be added
*/
public void addObject(Object object) {
_objects.add(object);
_lastElement = object;
}
/**
* Returns the last element (object) of the list
*
* @return object
*/
public Object getLastElement() {
return _lastElement;
}
/**
* Unmarshal of persistent objects.
*
* @param fileReader of the input XML file
* @param unmarshaller, optional
*
* @throws WSRPException
*/
public abstract void unMarshalFile(FileReader fileReader,
Unmarshaller unmarshaller)
throws WSRPException;
/**
* Marshal of persistent objects
*
* @param fileWriter to the output XML file
* @param marshaller, optional
*
* @throws WSRPException
*/
public abstract void marshalFile(
FileWriter fileWriter, Marshaller marshaller)
throws WSRPException;
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/PersistentHandlerImpl.java
Index: PersistentHandlerImpl.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
import org.apache.wsrp4j.commons.persistence.PersistentHandler;
import org.apache.wsrp4j.persistence.xml.PersistentDataObjectXML;
import org.apache.wsrp4j.persistence.xml.PersistentInformationXML;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
/**
* This class serves the store, restore and delete funtionality for
* PersistentDataObject XML files.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
* @version $Id: PersistentHandlerImpl.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class PersistentHandlerImpl implements PersistentHandler {
// holds this PersistentHandler
private static PersistentHandler _persistentHandler;
// map of filenames from XML files to the hashcode of the object
// key = hashcode, object = filename
private static HashMap _filenameMap = new HashMap();
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Create a PersistentHandler
*/
public static PersistentHandler create() {
if (_persistentHandler == null) {
_persistentHandler = new PersistentHandlerImpl();
}
return _persistentHandler;
}
/**
* Private Constructor
*/
private PersistentHandlerImpl() {
}
/**
* Store a single XML file, contained in the persistentDataObject to
* the persistent file store via the marshalFile method of the input
* object. The filename of the object is collected with it's hashcode
* internally.
*
* @param persistentDataObject
*
* @throws WSRPException
*/
public void store(PersistentDataObject persistentDataObject)
throws WSRPException {
String MN = "store";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
Mapping mapping = null;
Marshaller marshaller = null;
FileWriter fileWriter = null;
String filename = null;
try {
PersistentInformationXML persistentInformation =
(PersistentInformationXML) persistentDataObject.
getPersistentInformation();
Object o = persistentDataObject.getLastElement();
int hashCode = o.hashCode();
String code = new Integer(hashCode).toString();
filename = (String)_filenameMap.get(code);
if (filename == null) {
persistentInformation.updateFileName(code);
filename = persistentInformation.getFilename();
_filenameMap.put(code, filename);
}
File file = new File(filename);
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(Logger.TRACE_MEDIUM, MN, "Filename for store = " +
filename + "with code = " + code);
}
fileWriter = new FileWriter(file);
if (persistentInformation.getMappingFileName() != null) {
mapping = new Mapping();
mapping.loadMapping(persistentInformation.getMappingFileName());
marshaller = new Marshaller(fileWriter);
marshaller.setMapping(mapping);
}
((PersistentDataObjectXML)persistentDataObject).
marshalFile(fileWriter, marshaller);
fileWriter.close();
} catch (Exception e) {
// could not store object to persistent file
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.STORE_OBJECT_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Restores a single XML file into the persistentDataObject. The filename
* used is the filename stored in the PersistentFileInformation, contained
* in the PersistentDataObject.
*
* @param persistentDataObject
* @return PersistentDataObjct
*
* @throws WSRPException
*/
public PersistentDataObject restore(
PersistentDataObject persistentDataObject)
throws WSRPException {
String MN = "restore";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
Mapping mapping = null;
Unmarshaller unmarshaller = null;
try {
PersistentInformationXML persistentInformation =
(PersistentInformationXML) persistentDataObject.
getPersistentInformation();
if (persistentInformation.getMappingFileName() != null) {
mapping = new Mapping();
mapping.loadMapping(persistentInformation.getMappingFileName());
unmarshaller = new Unmarshaller(mapping);
}
File file = new File(persistentInformation.getFilename());
if (file.isFile()) {
FileReader fileReader = new FileReader(file);
try {
((PersistentDataObjectXML)persistentDataObject).
unMarshalFile(fileReader, unmarshaller);
fileReader.close();
Object o = persistentDataObject.getLastElement();
int hashCode = o.hashCode();
String code = new Integer(hashCode).toString();
_filenameMap.put(code, file.getAbsolutePath());
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(
Logger.TRACE_MEDIUM,
MN,
"File " + file.getAbsolutePath() +
" added with hashCode = " + code);
}
} catch (Exception e) {
// could not restore a single file from persistent store
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.RESTORE_OBJECT_ERROR, e);
}
}
} catch (Exception e) {
// castor persistent failure
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.RESTORE_OBJECT_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return persistentDataObject;
}
/**
* Restore all known XML files from the persistent store into the
* PersistentDataObject. The class type, which is part of the filename
* is stored in the PersistentInformation object of the
* PersistentDataObject.
*
* @param persistentDataObject
* @return PersistentDataObject
*
* @throws WSRPException
*/
public PersistentDataObject restoreMultiple(
PersistentDataObject persistentDataObject)
throws WSRPException {
String MN = "restoreMultiple";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
Mapping mapping = null;
Unmarshaller unmarshaller = null;
try {
PersistentInformationXML persistentInformation =
(PersistentInformationXML) persistentDataObject.
getPersistentInformation();
if (persistentInformation.getMappingFileName() != null) {
mapping = new Mapping();
mapping.loadMapping(persistentInformation.getMappingFileName());
unmarshaller = new Unmarshaller(mapping);
}
File file = new File(persistentInformation.getStoreDirectory());
if (file.exists()) {
File[] files = file.listFiles();
for (int x = 0; x < files.length; x++) {
if (files[x].isFile()) {
String currentFileName = files[x].getName();
// check for valid xml file
if (currentFileName.endsWith(persistentInformation.
getExtension())) {
// check for valid object
if (currentFileName.startsWith(
persistentInformation.getFilenameStub())) {
// load object
try {
FileReader fileReader =
new FileReader(files[x]);
((PersistentDataObjectXML) persistentDataObject).
unMarshalFile(fileReader, unmarshaller);
fileReader.close();
Object o = persistentDataObject.getLastElement();
int hashCode = o.hashCode();
String code = new Integer(hashCode).toString();
_filenameMap.put(code, files[x].getAbsolutePath());
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(
Logger.TRACE_MEDIUM,
MN,
"File " +
files[x].getAbsolutePath() +
" added with hashCode = " +
code);
}
} catch (Exception e) {
// restore error
WSRPXHelper.throwX(logger, Logger.ERROR,
MN,
ErrorCodes.RESTORE_OBJECT_ERROR, e);
}
}
}
}
}
}
} catch (Exception e) {
// restore error
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.RESTORE_OBJECT_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return persistentDataObject;
}
/**
* Delete the related XML persistent file of the input
* persistentDataObject information.
*
* @param persistentDataObject
*/
public void delete(PersistentDataObject persistentDataObject) {
String MN = "delete";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
Object o = persistentDataObject.getLastElement();
int hashCode = o.hashCode();
String code = new Integer(hashCode).toString();
String filename = (String)_filenameMap.get(code);
_filenameMap.remove(code);
File file = new File(filename);
if (file.exists()) {
file.delete();
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(Logger.TRACE_MEDIUM, MN, "Persistent file: "
+ filename + "deleted.");
}
} else {
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(Logger.TRACE_MEDIUM, MN,
"Try to delete persistent file: " +
filename + ". Not found!");
}
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/PersistentInformationImpl.java
Index: PersistentInformationImpl.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import java.io.File;
import org.apache.wsrp4j.persistence.xml.PersistentInformationXML;
/**
* Contains the persistent file store information for the castor
* xml file support. It's filled and returned initially by the class
* PersistentInformationProvider and used by the PersistentHandler
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
* @version $Id: PersistentInformationImpl.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class PersistentInformationImpl implements PersistentInformationXML {
// mapping file name
private String _mappingFileName;
// store directory
private String _storeDirectory;
// stub of the filename
private String _filenameStub;
// filename
private String _filename;
// grouping identifier
private String _groupID;
// file extension
private String _extension;
// file separator
private String _separator;
/**
* Constructor
*/
public PersistentInformationImpl() {
}
/**
* Set the Store directory for the persistent XML files
*
* @param storeDirectory String name of the store
*/
public void setStoreDirectory(String storeDirectory) {
_storeDirectory = storeDirectory;
}
/**
* Returns the directory for the persistent XML files
*
* @return String nanme of the store
*
*/
public String getStoreDirectory() {
return _storeDirectory;
}
/**
* Set the Castor XML mapping file name, fully qualified
*
* @param mappingFileName String fully qualified filename
*
*/
public void setMappingFileName(String mappingFileName) {
_mappingFileName = mappingFileName;
}
/**
* Returns the XML mapping file name, fully qualified
*
* @return String fully qualified filename
*
*/
public String getMappingFileName() {
return _mappingFileName;
}
/**
* Set the file name stub for persistent XML files. The name contains the
* store directory followed by a file separator and the class name of the
* object to be restored.
*
* @param stub String file name stub
*
*/
public void setFilenameStub(String stub) {
_filenameStub = stub;
}
/**
* Returns the file name stub for persistent XML files. @see setFilenameStub
*
* @return String file name stub
*
*/
public String getFilenameStub() {
return _filenameStub;
}
/**
* Returns a fully qualified file name for a persistent XML file.
*
* @return String file name
*
*/
public String getFilename() {
return _filename;
}
/**
* Set the fully qualified file name for a persistent XML file.
*
* @param filename String file name
*
*/
public void setFilename(String filename) {
_filename = filename;
}
/**
* Returns the group identifier, used in the filenames
*
* @return groupID as String
*
*/
public String getGroupID() {
return _groupID;
}
/**
* Set the group identifier, used in the filenames.
*
* @param groupID as String
*
*/
public void setGroupID(String groupID) {
_groupID = groupID;
}
/**
* Updates the file name, enhanced by a string token, like a handle to
* idportlet a unique persistent XML file. If a groupID is set, the
* groupID is used instead of the token to build the filename.
*
* @param token String token, like a handle
*
*/
public void updateFileName(String token) {
if (_groupID == null) {
_filename = getStoreDirectory() + File.separator +
getFilenameStub() + getSeparator() + token + getExtension();
} else {
_filename =
getStoreDirectory()
+ File.separator
+ getFilenameStub()
+ getSeparator()
+ getGroupID()
+ getExtension();
}
}
/**
* Returns the file extension used for persistent XML files
*
* @return String file extension
*
*/
public String getExtension() {
return _extension;
}
/**
* Set the file extension for persistent XML files.
*
* @param extension String file extension
*
*/
public void setExtension(String extension) {
_extension = extension;
}
/**
* Set the Separator, to be used in a fully qualified file name.
*
* @return String Separator character
*
*/
public String getSeparator() {
return _separator;
}
/**
* Set the separator character. (e.g. '@')
*
* @param separator String Separator character
*
*/
public void setSeparator(String separator) {
_separator = separator;
}
/**
* @return object as String
*/
public String toString() {
String lineSeparator = System.getProperty("line.separator");
return lineSeparator
+ "Mapping filename: "
+ _mappingFileName
+ lineSeparator
+ "Store directory : "
+ _storeDirectory
+ lineSeparator
+ "Filename stub : "
+ _filenameStub
+ lineSeparator
+ "Filename : "
+ _filename
+ lineSeparator
+ "Group ID : "
+ _groupID
+ lineSeparator
+ "Extension : "
+ _extension
+ lineSeparator
+ "Separator : "
+ _separator
+ lineSeparator;
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/PortletDescriptionList.java
Index: PortletDescriptionList.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import java.io.FileReader;
import java.io.FileWriter;
import oasis.names.tc.wsrp.v1.types.PortletDescription;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
/**
* This class collects PortletDescriptions and implements the
* marshal / unmarshal methods for CASTOR XML file support. Detailed
* information on persistent organizational data has to be requested
* with this class from the corresponding PersistentInformationProvider.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
* @version $Id: PortletDescriptionList.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class PortletDescriptionList extends PersistentDataObjectImpl {
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Default Constructor
*/
public PortletDescriptionList() {
}
/**
* Constructs a PortletDescription object from a CASTOR persistent
* XML file.
*
* @param fileReader to the input data file
*
* @param unmarshaller optional, part of the CASTOR package. In case of
* a null value as input parameter, the static methods
* of the CASTOR unmarshaller are used.
*
* @throws WSRPException
*/
public void unMarshalFile(FileReader fileReader, Unmarshaller unmarshaller)
throws WSRPException {
String MN = "unMarshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (unmarshaller == null) {
addObject(Unmarshaller.unmarshal(
PortletDescription.class, fileReader));
} else {
addObject(unmarshaller.unmarshal(fileReader));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.UNMARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Writes a PortletDescription, which must be the first element
* in the PersistentDataObject map, to a persistent XML file. In case
* of a null value as input parameter, the static methods of the CASTOR
* Marshaller are used.
*
* @param fileWriter to the output XML file
* @param marshaller, optional
*
* @throws WSRPException
*/
public void marshalFile(FileWriter fileWriter, Marshaller marshaller)
throws WSRPException {
String MN = "marshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (marshaller == null) {
Marshaller.marshal(_objects.get(0), fileWriter);
} else {
marshaller.marshal(_objects.get(0));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.MARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/PortletList.java
Index: PortletList.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import java.io.FileReader;
import java.io.FileWriter;
import org.apache.wsrp4j.commons.consumer.driver.WSRPPortletImpl;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
/**
* This class collects Portlets and implements the
* marshal / unmarshal methods for CASTOR XML file support. Detailed
* information on persistent organizational data has to be requested
* with this class from the corresponding PersistentInformationProvider.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
* @version $Id: PortletList.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class PortletList extends PersistentDataObjectImpl {
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Default Constructor
*/
public PortletList() {
}
/**
* Constructs a Portlet object from a CASTOR persistent
* XML file.
*
* @param fileReader to the input data file
*
* @param unmarshaller optional, part of the CASTOR package. In case of
* a null value as input parameter, the static methods
* of the CASTOR unmarshaller are used.
*
* @throws WSRPException
*/
public void unMarshalFile(FileReader fileReader, Unmarshaller unmarshaller)
throws WSRPException {
String MN = "unMarshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (unmarshaller == null) {
addObject(Unmarshaller.unmarshal(
WSRPPortletImpl.class, fileReader));
} else {
addObject(unmarshaller.unmarshal(fileReader));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.UNMARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Writes a Portlet, which must be the first element
* in the PersistentDataObject map, to a persistent XML file. In case
* of a null value as input parameter, the static methods of the CASTOR
* Marshaller are used.
*
* @param fileWriter to the output XML file
* @param marshaller, optional
*
* @throws WSRPException
*/
public void marshalFile(FileWriter fileWriter, Marshaller marshaller)
throws WSRPException {
String MN = "marshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (marshaller == null) {
Marshaller.marshal(_objects.get(0), fileWriter);
} else {
marshaller.marshal(_objects.get(0));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.MARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/ProducerList.java
Index: ProducerList.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import java.io.FileReader;
import java.io.FileWriter;
import org.apache.wsrp4j.commons.consumer.driver.ProducerImpl;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
/**
* This class collects Producer and implements the
* marshal / unmarshal methods for CASTOR XML file support. Detailed
* information on persistent organizational data has to be requested
* with this class from the corresponding PersistentInformationProvider.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
* @see PersistentHandler
* @see ProducerPersistentInformationProvider
*
* @version $Id: ProducerList.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class ProducerList extends PersistentDataObjectImpl {
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Default Constructor
*/
public ProducerList() {
}
/**
* Constructs a Producer object from a CASTOR persistent
* XML file.
*
* @param fileReader to the input data file
*
* @param unmarshaller optional, part of the CASTOR package. In case of
* a null value as input parameter, the static methods
* of the CASTOR unmarshaller are used.
*
* @throws WSRPException
*/
public void unMarshalFile(FileReader fileReader, Unmarshaller unmarshaller)
throws WSRPException {
String MN = "unMarshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (unmarshaller == null) {
addObject(Unmarshaller.unmarshal(
ProducerImpl.class, fileReader));
} else {
addObject(unmarshaller.unmarshal(fileReader));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.UNMARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Writes a Producer, which must be the first element
* in the PersistentDataObject map, to a persistent XML file. In case
* of a null value as input parameter, the static methods of the CASTOR
* Marshaller are used.
*
* @param fileWriter to the output XML file
* @param marshaller, optional
*
* @throws WSRPException
*/
public void marshalFile(FileWriter fileWriter, Marshaller marshaller)
throws WSRPException {
String MN = "marshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (marshaller == null) {
Marshaller.marshal(_objects.get(0), fileWriter);
} else {
marshaller.marshal(_objects.get(0));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.MARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/RegistrationList.java
Index: RegistrationList.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import java.io.FileReader;
import java.io.FileWriter;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.apache.wsrp4j.commons.producer.driver.RegistrationImpl;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
/**
* This class collects Registration objects and implements the
* marshal / unmarshal methods for CASTOR XML file support. Detailed
* information on persistent organizational data has to be requested
* with this class from the corresponding PersistentInformationProvider.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
* @see PersistentHandler
* @see ProducerPersistentInformationProvider
*
* @version $Id: RegistrationList.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class RegistrationList extends PersistentDataObjectImpl {
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Default Constructor
*/
public RegistrationList() {
}
/**
* Constructs a Registration object from a CASTOR persistent
* XML file.
*
* @param fileReader to the input data file
*
* @param unmarshaller optional, part of the CASTOR package. In case of
* a null value as input parameter, the static methods
* of the CASTOR unmarshaller are used.
*
* @throws WSRPException
*/
public void unMarshalFile(FileReader fileReader, Unmarshaller unmarshaller)
throws WSRPException {
String MN = "unMarshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (unmarshaller == null) {
addObject(Unmarshaller.unmarshal(
RegistrationImpl.class, fileReader));
} else {
addObject(unmarshaller.unmarshal(fileReader));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.UNMARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Writes a Registration, which must be the first element
* in the PersistentDataObject map, to a persistent XML file. In case
* of a null value as input parameter, the static methods of the CASTOR
* Marshaller are used.
*
* @param fileWriter to the output XML file
* @param marshaller, optional
*
* @throws WSRPException
*/
public void marshalFile(FileWriter fileWriter, Marshaller marshaller)
throws WSRPException {
String MN = "marshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (marshaller == null) {
Marshaller.marshal(_objects.get(0), fileWriter);
} else {
marshaller.marshal(_objects.get(0));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.MARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/ServerPersistentFactoryImpl.java
Index: ServerPersistentFactoryImpl.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
import org.apache.wsrp4j.commons.persistence.PersistentHandler;
import org.apache.wsrp4j.commons.persistence.PersistentInformationProvider;
import org.apache.wsrp4j.commons.persistence.ServerPersistentFactory;
import org.apache.wsrp4j.persistence.xml.ServerPersistentInformationProvider;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
/**
* This class is the server factory implementation for the persistence support.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
* @version $Id: ServerPersistentFactoryImpl.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class ServerPersistentFactoryImpl implements ServerPersistentFactory {
// holds this factory
private static ServerPersistentFactory serverPersistentFactory;
// holds the persistentHandler
private static PersistentHandler persistentHandler;
// holds the ServerPersistentInformationProvider
private static ServerPersistentInformationProvider serverInfoProvider;
// offset path for the persistent store
private String path = null;
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Returns a PersistentHandler
*
* @return persistentHandler
*/
public PersistentHandler getPersistentHandler() {
String MN = "getPersistentHandler";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
if (persistentHandler == null) {
persistentHandler = PersistentHandlerImpl.create();
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(Logger.TRACE_MEDIUM, MN,
"PersistentHandler successfully created.");
}
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return persistentHandler;
}
/**
* @return ServerPersistentInformationProvider
*/
public PersistentInformationProvider getPersistentInformationProvider() {
String MN = "getServerPersistentInformationProvider";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
if(serverInfoProvider == null && path == null) {
serverInfoProvider =
ServerPersistentInformationProviderImpl.create();
} else {
if(serverInfoProvider == null && path != null) {
serverInfoProvider =
ServerPersistentInformationProviderImpl.create(path);
}
}
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(Logger.TRACE_MEDIUM, MN,
"ServerPersistentInformationProvider successfully " +
"created.");
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return serverInfoProvider;
}
/**
* Set the real offset path of the persistent store
*
* @param path as string value
*/
public void setPath(String path) {
this.path = path;
}
/**
* Returns the PortletList
*
* @return PersistentDataObject
* @throws WSRPException
*/
public PersistentDataObject getPortletList() throws WSRPException {
String MN = "getPortletList";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
PortletList pdo = null;
try {
pdo = (PortletList) Class.forName(
"org.apache.wsrp4j.persistence.xml.driver." +
"PortletList").newInstance();
((ServerPersistentInformationProvider)
getPersistentInformationProvider()).getPersistentInformation(pdo);
} catch (Exception e) {
// could not find class
WSRPXHelper.throwX(logger, Logger.ERROR, MN, 1003, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return pdo;
}
/**
* Returns the ProducerList
*
* @return PersistentDataObject
* @throws WSRPException
*/
public PersistentDataObject getProducerList() throws WSRPException {
String MN = "getProducerList";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
ProducerList pdo = null;
try {
pdo = (ProducerList) Class.forName(
"org.apache.wsrp4j.persistence.xml.driver." +
"ProducerList").newInstance();
((ServerPersistentInformationProvider)
getPersistentInformationProvider()).getPersistentInformation(pdo);
} catch (Exception e) {
// could not find class
WSRPXHelper.throwX(logger, Logger.ERROR, MN, 1003, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return pdo;
}
/**
* Returns the RegistrationList
*
* @return PersistentDataObject
* @throws WSRPException
*/
public PersistentDataObject getRegistrationList() throws WSRPException {
String MN = "getRegistrationList";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
RegistrationList pdo = null;
try {
pdo = (RegistrationList) Class.forName(
"org.apache.wsrp4j.persistence.xml.driver." +
"RegistrationList").newInstance();
((ServerPersistentInformationProvider)
getPersistentInformationProvider()).getPersistentInformation(pdo);
} catch (Exception e) {
// could not find class
WSRPXHelper.throwX(logger, Logger.ERROR, MN, 1003, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return pdo;
}
/**
* Returns the UserList
*
* @return PersistentDataObject
* @throws WSRPException
*/
public PersistentDataObject getUserList() throws WSRPException {
String MN = "getUserList";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
UserList pdo = null;
try {
pdo = (UserList) Class.forName(
"org.apache.wsrp4j.persistence.xml.driver." +
"UserList").newInstance();
((ServerPersistentInformationProvider)
getPersistentInformationProvider()).getPersistentInformation(pdo);
} catch (Exception e) {
// could not find class
WSRPXHelper.throwX(logger, Logger.ERROR, MN, 1003, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return pdo;
}
/**
* Returns the ConsumerConfiguredPortletList
*
* @return PersistentDataObject
* @throws WSRPException
*/
public PersistentDataObject getConsumerConfiguredPortletList()
throws WSRPException {
String MN = "getConsumerConfiguredPortletList";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
ConsumerConfiguredPortletList pdo = null;
try {
pdo = (ConsumerConfiguredPortletList) Class.forName(
"org.apache.wsrp4j.persistence.xml.driver." +
"ConsumerConfiguredPortletList").
newInstance();
((ServerPersistentInformationProvider)
getPersistentInformationProvider()).getPersistentInformation(pdo);
} catch (Exception e) {
// could not find class
WSRPXHelper.throwX(logger, Logger.ERROR, MN, 1003, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return pdo;
}
/**
* Returns the PortletDescriptionList
*
* @return PersistentDataObject
* @throws WSRPException
*/
public PersistentDataObject getPortletDescriptionList()
throws WSRPException {
String MN = "getPortletDescriptionList";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
PortletDescriptionList pdo = null;
try {
pdo = (PortletDescriptionList) Class.forName(
"org.apache.wsrp4j.persistence.xml.driver." +
"PortletDescriptionList").
newInstance();
((ServerPersistentInformationProvider)
getPersistentInformationProvider()).getPersistentInformation(pdo);
} catch (Exception e) {
// could not find class
WSRPXHelper.throwX(logger, Logger.ERROR, MN, 1003, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return pdo;
}
/**
* Returns the ServiceDescriptionList
*
* @return PersistentDataObject
* @throws WSRPException
*/
public PersistentDataObject getServiceDescriptionList()
throws WSRPException {
String MN = "getServiceDescriptionList";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
ServiceDescriptionList pdo = null;
try {
pdo = (ServiceDescriptionList) Class.forName(
"org.apache.wsrp4j.persistence.xml.driver." +
"ServiceDescriptionList").
newInstance();
((ServerPersistentInformationProvider)
getPersistentInformationProvider()).getPersistentInformation(pdo);
} catch (Exception e) {
// could not find class
WSRPXHelper.throwX(logger, Logger.ERROR, MN, 1003, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return pdo;
}
/**
* Returns the ConsumerPortletRegistrationList
*
* @return PersistentDataObject
* @throws WSRPException
*/
public PersistentDataObject getConsumerPortletRegistrationList()
throws WSRPException {
String MN = "getConsumerPortletRegistrationList";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
ConsumerPortletRegistrationList pdo = null;
try {
pdo = (ConsumerPortletRegistrationList) Class.forName(
"org.apache.wsrp4j.persistence.xml.driver." +
"ConsumerPortletRegistrationList").
newInstance();
((ServerPersistentInformationProvider)
getPersistentInformationProvider()).getPersistentInformation(pdo);
} catch (Exception e) {
// could not find class
WSRPXHelper.throwX(logger, Logger.ERROR, MN, 1003, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return pdo;
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/ServerPersistentInformationProviderImpl.java
Index: ServerPersistentInformationProviderImpl.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import java.io.File;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import oasis.names.tc.wsrp.v1.types.PortletDescription;
import org.apache.axis.AxisEngine;
import org.apache.axis.MessageContext;
import org.apache.axis.transport.http.HTTPConstants;
import org.apache.wsrp4j.commons.consumer.driver.ProducerImpl;
import org.apache.wsrp4j.commons.consumer.driver.UserImpl;
import org.apache.wsrp4j.commons.consumer.driver.WSRPPortletImpl;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.apache.wsrp4j.commons.producer.Registration;
import org.apache.wsrp4j.commons.producer.driver.RegistrationImpl;
import org.apache.wsrp4j.commons.producer.provider.driver.
ConsumerConfiguredPortletImpl;
import org.apache.wsrp4j.commons.producer.provider.driver.
ConsumerPortletRegistrationImpl;
import org.apache.wsrp4j.commons.persistence.PersistentInformation;
import org.apache.wsrp4j.commons.persistence.driver.WSRPServiceDescription;
import org.apache.wsrp4j.persistence.xml.PersistentInformationXML;
import org.apache.wsrp4j.persistence.xml.ServerPersistentInformationProvider;
/**
* This class holds the information for persistent file handling centrally. It
* creates the persistent file store directory during construction and returns
* PersistentFileInformation objects, filled with directory and file name
* information, based on the request.
*
* The file system structure looks like:
*
* 1) the PROVIDER case:
*
* ./persistence/*.xml (contains the mapping XML files)
* ./persistence/portlets/*.xml (contains object XML files)
* ./persistence/descriptions/*.xml (contains object XML files)
* ./persistence/portletStates/*.xml (contains object XML files)
* ./persistence/registries/*.xml (contains object XML files)
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
* @version $Id: ServerPersistentInformationProviderImpl.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class ServerPersistentInformationProviderImpl
implements ServerPersistentInformationProvider {
private ServerPersistentInformationProvider _persistentInfoProvider;
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
// sub directory for descriptions
private static final String DESCRIPTIONS = "descriptions";
// sub directory for descriptions
private static final String PORTLETS = "portlets";
// sub directory for descriptions
private static final String PORTLETSTATES = "portletstates";
// sub directory for descriptions
private static final String REGISTRIES = "registries";
// sub directory for users
private static final String USERS = "users";
// sub directory for producers
private static final String PRODUCERS = "producers";
// user mapping file name
private static final String USER_MAPPING = "UserMapping";
// producer mapping file name
private static final String PRODUCER_MAPPING = "ProducerMapping";
// portlet mapping file name
private static final String PORTLET_MAPPING = "PortletMapping";
// mapping file name of the servicedescription
private static final String SERVICE_DESCRIPTION_MAPPING =
"ServiceDescriptionMapping";
// mapping file name of the registry
private static final String REGISTRY_MAPPING = "RegistryMapping";
// mapping file name of the portlet (pluto)
private static final String PLUTO_PORTLET_MAPPING = "PlutoPortletMapping";
// mapping file name of the portlet (pluto)
private static final String SIMPLE_PORTLET_MAPPING = "SimplePortletMapping";
// mapping file name of the portlet states
private static final String PORTLET_STATE_MAPPING = "PortletStateMapping";
// This will be the root of all the persistent files
// it should end up looking soemthing like this:
// c:/Program Files/Tomcat 4.0/webapps/WEB-INF/persistence
// depending on the installation
private static String ROOT_DIR = null;
// File extension of the portlet persistent file store files
private static String FILE_EXTENSION = ".xml";
// sub directory, sub-root of the persistent file store
private static String PERSISTENT_DIR = "persistence";
// Separator in the filename of the portlet persistent file store
private static String SEPARATOR = "@";
/**
* Static construction of the PersistentInformationProvider
*/
public static ServerPersistentInformationProvider create() {
return new ServerPersistentInformationProviderImpl();
}
/**
* @param offsetPath path for the store directory to be used
*
* Static construction of the PersistentInformationProvider
*/
public static ServerPersistentInformationProvider create(
String offsetPath) {
return new ServerPersistentInformationProviderImpl(offsetPath);
}
/**
* Private constructor
*/
private ServerPersistentInformationProviderImpl() {
logger.entry(Logger.TRACE_HIGH, "Constructor");
try {
if (ROOT_DIR == null) {
// ROOT_DIR is static, so it only needs to be setup once for all
// instances of PersistentStore objects
// get the servlet context so we can figure out where to put the
// files based on the context root of the web application
// this is a bit of a hack since it will only work for servlet
// based deployments, but this is how Axis computes the
// location of the server-config.wsdd, so we can too
String path = null;
try {
MessageContext msgContext =
AxisEngine.getCurrentMessageContext();
HttpServlet servlet =
(HttpServlet)msgContext.getProperty(
HTTPConstants.MC_HTTP_SERVLET);
ServletContext servletContext = servlet.getServletContext();
// use WEB-INF because http clients can't see it
path = servletContext.getRealPath("/WEB-INF") +
File.separator;
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(Logger.TRACE_MEDIUM, "Constructor",
"Current path of servletContext = " + path);
}
} catch (Exception e) {
// ignore
}
if (path == null) {
ROOT_DIR = PERSISTENT_DIR;
} else {
ROOT_DIR = path + PERSISTENT_DIR;
}
}
} catch (Exception e) {
e.printStackTrace();
}
logger.exit(Logger.TRACE_HIGH, "Constructor");
}
/**
* Private constructor
*/
public ServerPersistentInformationProviderImpl(String offsetPath) {
logger.entry(Logger.TRACE_HIGH, "Constructor");
try {
if (ROOT_DIR == null) {
// ROOT_DIR is static, so it only needs to be setup once for all
// instances of PersistentStore objects
ROOT_DIR = offsetPath + File.separator + PERSISTENT_DIR;
}
} catch (Exception e) {
e.printStackTrace();
}
logger.exit(Logger.TRACE_HIGH, "Constructor");
}
/**
* Returns the store directory with the given sub directory
*
* @param subDirectory String sub directory
*
* @return String store directory
*
*/
public String getStoreDirectory(String subDirectory) {
return ROOT_DIR + File.separator + subDirectory;
}
/**
* Creates the store directory with the given sub directory name
*
* @param subDirectory String sub directory
*
*/
public void makeStoreSubDir(String subDirectory) {
// make sure the store directory exists
File file = new File(ROOT_DIR + File.separator + subDirectory);
if (!file.exists()) {
file.mkdir();
}
}
/**
* Compute the path to the mapping file from the root plus the name of the
* mapping file
*
* @param mappingBaseName String mapping file base name without extension
*
* @return String fully qualified mapping file name with extension
*/
public String getMappingFile(String mappingBaseName) {
String mappingFile = new String(ROOT_DIR + File.separator +
mappingBaseName + FILE_EXTENSION);
return mappingFile;
}
/**
* Returns the persistent file information for the ServiceDescription
*
* @param serviceDescriptionList ServiceDescriptionList
*
* @return PersistentInformation
*/
public PersistentInformation getPersistentInformation(
ServiceDescriptionList serviceDescriptionList) {
logger.entry(Logger.TRACE_HIGH, "getPersistentInformation");
PersistentInformationXML persistentInfo = null;
if (serviceDescriptionList != null) {
persistentInfo = new PersistentInformationImpl();
persistentInfo.setStoreDirectory(getStoreDirectory(DESCRIPTIONS));
persistentInfo.setMappingFileName(getMappingFile(
SERVICE_DESCRIPTION_MAPPING));
WSRPServiceDescription serviceDescription =
new WSRPServiceDescription();
persistentInfo.setFilenameStub(
serviceDescription.getClass().getName());
persistentInfo.setFilename(
persistentInfo.getStoreDirectory()
+ File.separator
+ serviceDescription.getClass().getName()
+ FILE_EXTENSION);
persistentInfo.setExtension(FILE_EXTENSION);
persistentInfo.setSeparator(SEPARATOR);
serviceDescriptionList.setPersistentInformation(persistentInfo);
makeStoreSubDir(DESCRIPTIONS);
}
logger.exit(Logger.TRACE_HIGH, "getPersistentInformation");
return persistentInfo;
}
/**
* Returns the persistent file information for the PortletDescription
*
* @param portletDescriptionList PortletDescriptionList
*
* @return PersistentInformation
**/
public PersistentInformation getPersistentInformation(
PortletDescriptionList portletDescriptionList) {
logger.entry(Logger.TRACE_HIGH, "getPersistentInformation");
PersistentInformationXML persistentInfo = null;
if (portletDescriptionList != null) {
persistentInfo = new PersistentInformationImpl();
persistentInfo.setStoreDirectory(getStoreDirectory(DESCRIPTIONS));
persistentInfo.setMappingFileName(null);
PortletDescription portletDescription = new PortletDescription();
persistentInfo.setFilenameStub(portletDescription.getClass().
getName());
persistentInfo.setFilename(null);
persistentInfo.setExtension(FILE_EXTENSION);
persistentInfo.setSeparator(SEPARATOR);
portletDescriptionList.setPersistentInformation(persistentInfo);
makeStoreSubDir(DESCRIPTIONS);
}
logger.exit(Logger.TRACE_HIGH, "getPersistentInformation");
return persistentInfo;
}
/**
* Returns the persistent file information for the Registration
*
* @param registrationList RegistrationList
*
* @return PersistentInformation
**/
public PersistentInformation getPersistentInformation(
RegistrationList registrationList) {
logger.entry(Logger.TRACE_HIGH, "getPersistentInformation");
PersistentInformationXML persistentInfo = null;
if (registrationList != null) {
persistentInfo = new PersistentInformationImpl();
persistentInfo.setStoreDirectory(getStoreDirectory(REGISTRIES));
persistentInfo.setMappingFileName(getMappingFile(REGISTRY_MAPPING));
Registration registration = new RegistrationImpl();
persistentInfo.setFilenameStub(registration.getClass().getName());
persistentInfo.setFilename(null);
persistentInfo.setExtension(FILE_EXTENSION);
persistentInfo.setSeparator(SEPARATOR);
registrationList.setPersistentInformation(persistentInfo);
makeStoreSubDir(REGISTRIES);
}
logger.exit(Logger.TRACE_HIGH, "getPersistentInformation");
return persistentInfo;
}
/**
* Returns the persistent file information for the ConsumerConfiguredPortlet
*
* @param cceList ConsumerConfiguredPortletList
*
* @return PersistentInformation
**/
public PersistentInformation getPersistentInformation(
ConsumerConfiguredPortletList cceList) {
logger.entry(Logger.TRACE_HIGH, "getPersistentInformation");
PersistentInformationXML persistentInfo = null;
if (cceList != null) {
persistentInfo = new PersistentInformationImpl();
persistentInfo.setStoreDirectory(getStoreDirectory(PORTLETS));
persistentInfo.setMappingFileName(getMappingFile(
PLUTO_PORTLET_MAPPING));
ConsumerConfiguredPortletImpl cce =
new ConsumerConfiguredPortletImpl();
persistentInfo.setFilenameStub(cce.getClass().getName());
persistentInfo.setFilename(null);
persistentInfo.setExtension(FILE_EXTENSION);
persistentInfo.setSeparator(SEPARATOR);
cceList.setPersistentInformation(persistentInfo);
makeStoreSubDir(PORTLETS);
}
logger.exit(Logger.TRACE_HIGH, "getPersistentInformation");
return persistentInfo;
}
/**
* Returns the persistent file information for the producers
*
* @param producerList
*
* @return PersistentInformation
*/
public PersistentInformation getPersistentInformation(
ProducerList producerList) {
logger.entry(Logger.TRACE_HIGH, "getPersistentInformation");
PersistentInformationXML persistentInfo = null;
if (producerList != null) {
persistentInfo = new PersistentInformationImpl();
persistentInfo.setStoreDirectory(getStoreDirectory(PRODUCERS));
persistentInfo.setMappingFileName(getMappingFile(PRODUCER_MAPPING));
ProducerImpl producer = new ProducerImpl();
persistentInfo.setFilenameStub(producer.getClass().getName());
persistentInfo.setFilename(null);
persistentInfo.setExtension(FILE_EXTENSION);
persistentInfo.setSeparator(SEPARATOR);
producerList.setPersistentInformation(persistentInfo);
makeStoreSubDir(PRODUCERS);
}
logger.exit(Logger.TRACE_HIGH, "getPersistentInformation");
return persistentInfo;
}
/**
* Returns the persistent file information for the user
*
* @param userList
*
* @return PersistentInformation
*/
public PersistentInformation getPersistentInformation(UserList userList) {
logger.entry(Logger.TRACE_HIGH, "getPersistentInformation");
PersistentInformationXML persistentInfo = null;
if (userList != null) {
persistentInfo = new PersistentInformationImpl();
persistentInfo.setStoreDirectory(getStoreDirectory(USERS));
persistentInfo.setMappingFileName(getMappingFile(USER_MAPPING));
UserImpl user = new UserImpl();
persistentInfo.setFilenameStub(user.getClass().getName());
persistentInfo.setFilename(null);
persistentInfo.setExtension(FILE_EXTENSION);
persistentInfo.setSeparator(SEPARATOR);
userList.setPersistentInformation(persistentInfo);
makeStoreSubDir(USERS);
}
logger.exit(Logger.TRACE_HIGH, "getPersistentInformation");
return persistentInfo;
}
/**
* Returns the persistent file information for the Portlet
*
* @param portletList
*
* @return PersistentInformation
*/
public PersistentInformation getPersistentInformation(
PortletList portletList) {
logger.entry(Logger.TRACE_HIGH, "getPersistentInformation");
PersistentInformationXML persistentInfo = null;
if (portletList != null) {
persistentInfo = new PersistentInformationImpl();
persistentInfo.setStoreDirectory(getStoreDirectory(PORTLETS));
persistentInfo.setMappingFileName(getMappingFile(PORTLET_MAPPING));
WSRPPortletImpl portlet = new WSRPPortletImpl();
persistentInfo.setFilenameStub(portlet.getClass().getName());
persistentInfo.setFilename(null);
persistentInfo.setExtension(FILE_EXTENSION);
persistentInfo.setSeparator(SEPARATOR);
portletList.setPersistentInformation(persistentInfo);
makeStoreSubDir(PORTLETS);
}
logger.exit(Logger.TRACE_HIGH, "getPersistentInformation");
return persistentInfo;
}
/**
* Returns the persistent file information for the
* ConsumerPortletRegistrationList
*
* @param regList
*
* @return PersistentInformation
*/
public PersistentInformation getPersistentInformation(
ConsumerPortletRegistrationList regList) {
logger.entry(Logger.TRACE_HIGH, "getPersistentInformation");
PersistentInformationXML persistentInfo = null;
if (regList != null) {
persistentInfo = new PersistentInformationImpl();
persistentInfo.setStoreDirectory(getStoreDirectory(REGISTRIES));
persistentInfo.setMappingFileName(null);
ConsumerPortletRegistrationImpl cpr =
new ConsumerPortletRegistrationImpl();
persistentInfo.setFilenameStub(cpr.getClass().getName());
persistentInfo.setFilename(null);
persistentInfo.setExtension(FILE_EXTENSION);
persistentInfo.setSeparator(SEPARATOR);
regList.setPersistentInformation(persistentInfo);
makeStoreSubDir(REGISTRIES);
}
logger.exit(Logger.TRACE_HIGH, "getPersistentInformation");
return persistentInfo;
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/ServiceDescriptionList.java
Index: ServiceDescriptionList.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import java.io.FileReader;
import java.io.FileWriter;
import oasis.names.tc.wsrp.v1.types.ServiceDescription;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
/**
* This class contains a ServiceDescription and implements the
* marshal / unmarshal methods for CASTOR XML file support. Detailed
* information on persistent organizational data has to be requested
* with this class from the corresponding PersistentInformationProvider.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
* @see PersistentHandler
* @see ProducerPersistentInformationProvider
*
* @version $Id: ServiceDescriptionList.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class ServiceDescriptionList extends PersistentDataObjectImpl {
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Default Constructor
*/
public ServiceDescriptionList() {
}
/**
* Constructs a ServiceDescription object from a CASTOR persistent
* XML file.
*
* @param fileReader to the input data file
*
* @param unmarshaller optional, part of the CASTOR package. In case of
* a null value as input parameter, the static methods
* of the CASTOR unmarshaller are used.
*
* @throws WSRPException
*/
public void unMarshalFile(FileReader fileReader, Unmarshaller unmarshaller)
throws WSRPException {
String MN = "unMarshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (unmarshaller == null) {
addObject(Unmarshaller.unmarshal(
ServiceDescription.class, fileReader));
} else {
addObject(unmarshaller.unmarshal(fileReader));
}
} catch (Exception e) {
e.printStackTrace();
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.UNMARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Writes a ServiceDescription, which must be the first element
* in the PersistentDataObject map, to a persistent XML file. In case
* of a null value as input parameter, the static methods of the CASTOR
* Marshaller are used.
*
* @param fileWriter to the output XML file
* @param marshaller, optional
*
* @throws WSRPException
*/
public void marshalFile(FileWriter fileWriter, Marshaller marshaller)
throws WSRPException {
String MN = "marshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (marshaller == null) {
Marshaller.marshal(_objects.get(0), fileWriter);
} else {
marshaller.marshal(_objects.get(0));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.MARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/UserList.java
Index: UserList.java
===================================================================
/*
* Copyright 2003-2005 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 org.apache.wsrp4j.persistence.xml.driver;
import java.io.FileReader;
import java.io.FileWriter;
import org.apache.wsrp4j.commons.consumer.driver.UserImpl;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
/**
* This class collects Users and implements the
* marshal / unmarshal methods for CASTOR XML file support. Detailed
* information on persistent organizational data has to be requested
* with this class from the corresponding PersistentInformationProvider.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
* @see PersistentHandler
* @see ProducerPersistentInformationProvider
*
* @version $Id: UserList.java,v 1.1 2005/08/28 22:53:01 dlouzan Exp $
*/
public class UserList extends PersistentDataObjectImpl {
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Default Constructor
*/
public UserList() {
}
/**
* Constructs a User object from a CASTOR persistent
* XML file.
*
* @param fileReader to the input data file
*
* @param unmarshaller optional, part of the CASTOR package. In case of
* a null value as input parameter, the static methods
* of the CASTOR unmarshaller are used.
*
*/
public void unMarshalFile(FileReader fileReader, Unmarshaller unmarshaller)
throws WSRPException {
String MN = "unMarshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (unmarshaller == null) {
addObject(Unmarshaller.unmarshal(UserImpl.class, fileReader));
} else {
addObject(unmarshaller.unmarshal(fileReader));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.UNMARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Writes a User, which must be the first element
* in the PersistentDataObject map, to a persistent XML file. In case
* of a null value as input parameter, the static methods of the CASTOR
* Marshaller are used.
*
* @param fileWriter to the output XML file
* @param marshaller, optional
*/
public void marshalFile(FileWriter fileWriter, Marshaller marshaller)
throws WSRPException {
String MN = "marshalFile";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
if (marshaller == null) {
Marshaller.marshal(_objects.get(0), fileWriter);
} else {
marshaller.marshal(_objects.get(0));
}
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.MARSHAL_ERROR, e);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
}