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/31 19:36:00 UTC
cvs commit: ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver PageList.java ClientPersistentFactoryImpl.java ClientPersistentInformationProviderImpl.java ConsumerPortletContextList.java
dlouzan 2005/08/31 10:36:00
Added: sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver
PageList.java ClientPersistentFactoryImpl.java
ClientPersistentInformationProviderImpl.java
ConsumerPortletContextList.java
Log:
Initial commit.
Revision Changes Path
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/PageList.java
Index: PageList.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.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
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.consumer.driver.PageImpl;
/**
* This class collects Pages 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: PageList.java,v 1.1 2005/08/31 17:36:00 dlouzan Exp $
*/
public class PageList extends PersistentDataObjectImpl {
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Default Constructor
*/
public PageList() {
}
/**
* Constructs a Page 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(PageImpl.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 Page, 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/ClientPersistentFactoryImpl.java
Index: ClientPersistentFactoryImpl.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.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.ClientPersistentFactory;
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.persistence.xml.ClientPersistentInformationProvider;
/**
* This class is the client factory implementation for the persistence support.
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
*
* @version $Id: ClientPersistentFactoryImpl.java,v 1.1 2005/08/31 17:36:00 dlouzan Exp $
*/
public class ClientPersistentFactoryImpl implements ClientPersistentFactory {
// holds this factory
private static ClientPersistentFactory persistentFactory;
// holds the PersistentHandler
private static PersistentHandler persistentHandler;
// holds the ClientPersistentInformationProvider
private static ClientPersistentInformationProvider clientInfoProvider;
// 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;
}
/**
* Returns a ServerPersistentInformationrovider
*
* @return ServerPersistentInformationProvider
*/
public PersistentInformationProvider getPersistentInformationProvider() {
String MN = "getClientPersistentInformationProvider";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
if(clientInfoProvider == null) {
clientInfoProvider =
ClientPersistentInformationProviderImpl.create();
}
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(Logger.TRACE_MEDIUM, MN,
"ClientPersistentInformationProvider successfully " +
"created.");
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return clientInfoProvider;
}
/**
* 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();
((ClientPersistentInformationProvider)
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 ConsumerPortletContextList
*
* @return PersistentDataObject
* @throws WSRPException
*/
public PersistentDataObject getConsumerPortletContextList()
throws WSRPException {
String MN = "getConsumerPortletContextList";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
ConsumerPortletContextList pdo = null;
try {
pdo = (ConsumerPortletContextList) Class.forName(
"org.apache.wsrp4j.persistence.xml.driver." +
"ConsumerPortletContextList").newInstance();
((ClientPersistentInformationProvider)
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();
((ClientPersistentInformationProvider)
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 PageList
*
* @return PersistentDataObject
* @throws WSRPException
*/
public PersistentDataObject getPageList() throws WSRPException {
String MN = "getPageList";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
PageList pdo = null;
try {
pdo = (PageList) Class.forName(
"org.apache.wsrp4j.persistence.xml.driver." +
"PageList").newInstance();
((ClientPersistentInformationProvider)
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();
((ClientPersistentInformationProvider)
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/ClientPersistentInformationProviderImpl.java
Index: ClientPersistentInformationProviderImpl.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.IOException;
import java.io.InputStream;
import org.apache.wsrp4j.commons.consumer.driver.ConsumerPortletContext;
import org.apache.wsrp4j.commons.consumer.driver.PageImpl;
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.persistence.PersistentInformation;
import org.apache.wsrp4j.persistence.xml.PersistentInformationXML;
import org.apache.wsrp4j.persistence.xml.ClientPersistentInformationProvider;
/**
* Consumer:
*
* This class holds the information for persistent file handling centrally. It
* creates the persistent file store directory on demand and returns
* PersistentFileInformation objects, filled with directory and file name
* information, based on the request.
*
* The file system structure looks like:
*
* 1) the CONSUMER case:
*
* ./persistence/*.xml (contains the mapping XML files)
* ./persistence/portlets/*.xml (contains object XML files)
* ./persistence/pages/*.xml (contains object XML files)
* ./persistence/users/*.xml (contains object XML files)
* ./persistence/producers/*.xml (contains object XML files)
*
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
* @version $Id: ClientPersistentInformationProviderImpl.java,v 1.1 2005/08/31 17:36:00 dlouzan Exp $
*/
public class ClientPersistentInformationProviderImpl
implements ClientPersistentInformationProvider {
// holds this provider
private ClientPersistentInformationProvider _persistentInfoProvider;
private static final String CONSUMER_PERSISTENTSTORE =
"consumer.persistentstore";
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
// sub directory for entites
private static final String PORTLETS = "portlets";
// sub directory for users
private static final String USERS = "users";
// sub directory for pages
private static final String PAGES = "pages";
// sub directory for producers
private static final String PRODUCERS = "producers";
// portlet mapping file name
private static final String PORTLET_MAPPING = "PortletMapping";
// portlet mapping file name
private static final String PAGE_MAPPING = "PageMapping";
// user mapping file name
private static final String USER_MAPPING = "UserMapping";
// producer mapping file name
private static final String PRODUCER_MAPPING = "ProducerMapping";
// 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 ClientPersistentInformationProvider create() {
return new ClientPersistentInformationProviderImpl();
}
/**
* Private constructor
*
* Creates the persistent file store directories dependent on the
* configured persistent store directory in the consumer properties file.
* If no persistent store directory was specified, the current runtime
* directory will be used as the root directory.
*/
private ClientPersistentInformationProviderImpl() {
File file = null;
String StoreDir = null;
try {
InputStream is = this.getClass().getClassLoader().
getResourceAsStream("SwingConsumer.properties");
java.util.Properties props = new java.util.Properties();
if (is != null) {
props.load(is);
StoreDir = (String)props.get(CONSUMER_PERSISTENTSTORE);
is.close();
}
} catch (IOException e) {
}
// store directroy in properties file found?
if (StoreDir != null) {
// check on trailing file separator in file name
if (StoreDir.endsWith(File.separator)) {
StoreDir = StoreDir.concat(File.separator);
}
// build root directory plus persistent dir
ROOT_DIR = StoreDir + PERSISTENT_DIR;
} else {
// No configuration or properties file found, use default value
file = new File("");
ROOT_DIR = file.getAbsolutePath();
ROOT_DIR = ROOT_DIR + File.separator + PERSISTENT_DIR;
}
// create persistent directory
file = new File(ROOT_DIR);
file.mkdir();
// make store directories
// makeStoreSubDir(PAGES);
// makeStoreSubDir(PRODUCERS);
// makeStoreSubDir(PORTLETS);
// makeStoreSubDir(USERS);
}
/**
* Returns the store directory with the given sub directory
*
* @param subDirectory String sub directory
*
* @return String store directory
*/
private 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
*
*/
private 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
*/
private String getMappingFile(String mappingBaseName) {
String mappingFile = new String(ROOT_DIR + File.separator +
mappingBaseName + FILE_EXTENSION);
return mappingFile;
}
/**
* Returns the persistent file information for the Portlet
*
* @param portletList
*
* @return PersistentInformation
*/
public PersistentInformation getPersistentInformation(
PortletList portletList) {
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);
}
return persistentInfo;
}
/**
* Returns the persistent file information for the Page
*
* @param pageList
*
* @return PersistentInformation
*/
public PersistentInformation getPersistentInformation(PageList pageList) {
PersistentInformationXML persistentInfo = null;
if (pageList != null) {
persistentInfo = new PersistentInformationImpl();
persistentInfo.setStoreDirectory(getStoreDirectory(PAGES));
persistentInfo.setMappingFileName(getMappingFile(PAGE_MAPPING));
PageImpl page = new PageImpl();
persistentInfo.setFilenameStub(page.getClass().getName());
persistentInfo.setFilename(null);
persistentInfo.setExtension(FILE_EXTENSION);
persistentInfo.setSeparator(SEPARATOR);
pageList.setPersistentInformation(persistentInfo);
makeStoreSubDir(PAGES);
}
return persistentInfo;
}
/**
* Returns the persistent file information for the user
*
* @param userList
*
* @return PersistentInformation
*/
public PersistentInformation getPersistentInformation(UserList userList) {
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);
}
return persistentInfo;
}
/**
* Returns the persistent file information for the producers
*
* @param producerList
*
* @return PersistentInformation
*/
public PersistentInformation getPersistentInformation(
ProducerList producerList) {
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);
}
return persistentInfo;
}
/**
* Returns the persistent file information for the ConsumerPortletContext
*
* @param consumerPortletContextList ConsumerPortletContextList
*
* @return PersistentInformation
*/
public PersistentInformation getPersistentInformation(
ConsumerPortletContextList consumerPortletContextList) {
PersistentInformationXML persistentInfo = null;
if (consumerPortletContextList != null) {
persistentInfo = new PersistentInformationImpl();
persistentInfo.setStoreDirectory(getStoreDirectory(PORTLETS));
persistentInfo.setMappingFileName(null);
ConsumerPortletContext consumerPortletContext =
new ConsumerPortletContext();
persistentInfo.setFilenameStub(
consumerPortletContext.getClass().getName());
persistentInfo.setFilename(null);
persistentInfo.setExtension(FILE_EXTENSION);
persistentInfo.setSeparator(SEPARATOR);
consumerPortletContextList.setPersistentInformation(persistentInfo);
makeStoreSubDir(PORTLETS);
}
return persistentInfo;
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/persistence-xml/src/java/org/apache/wsrp4j/persistence/xml/driver/ConsumerPortletContextList.java
Index: ConsumerPortletContextList.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.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
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.consumer.driver.ConsumerPortletContext;
/**
* This class collects ConsumerPortletContext 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: ConsumerPortletContextList.java,v 1.1 2005/08/31 17:36:00 dlouzan Exp $
*/
public class ConsumerPortletContextList extends PersistentDataObjectImpl {
// log and trace support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* Default Constructor
*/
public ConsumerPortletContextList() {
}
/**
* Constructs a ConsumerPortletContext 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(ConsumerPortletContext.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 an ConsumerPortletContext, 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);
}
}
}