code stringlengths 1 2.01M | repo_name stringlengths 3 62 | path stringlengths 1 267 | language stringclasses 231
values | license stringclasses 13
values | size int64 1 2.01M |
|---|---|---|---|---|---|
/*
* Copyright (C) 2010 Alessio Gaeta <alessio.gaeta@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.connectionmanager.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.controlpoint.ControlPoint;
import org.teleal.cling.model.ServiceReference;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.support.model.ConnectionInfo;
import org.teleal.cling.support.model.ProtocolInfo;
/**
* @author Alessio Gaeta
* @author Christian Bauer
*/
public abstract class PrepareForConnection extends ActionCallback {
public PrepareForConnection(Service service,
ProtocolInfo remoteProtocolInfo, ServiceReference peerConnectionManager,
int peerConnectionID, ConnectionInfo.Direction direction) {
this(service, null, remoteProtocolInfo, peerConnectionManager, peerConnectionID, direction);
}
public PrepareForConnection(Service service, ControlPoint controlPoint,
ProtocolInfo remoteProtocolInfo, ServiceReference peerConnectionManager,
int peerConnectionID, ConnectionInfo.Direction direction) {
super(new ActionInvocation(service.getAction("PrepareForConnection")), controlPoint);
getActionInvocation().setInput("RemoteProtocolInfo", remoteProtocolInfo.toString());
getActionInvocation().setInput("PeerConnectionManager", peerConnectionManager.toString());
getActionInvocation().setInput("PeerConnectionID", peerConnectionID);
getActionInvocation().setInput("Direction", direction.toString());
}
@Override
public void success(ActionInvocation invocation) {
received(
invocation,
(Integer)invocation.getOutput("ConnectionID").getValue(),
(Integer)invocation.getOutput("RcsID").getValue(),
(Integer)invocation.getOutput("AVTransportID").getValue()
);
}
public abstract void received(ActionInvocation invocation, int connectionID, int rcsID, int avTransportID);
}
| zzh84615-mycode | src/org/teleal/cling/support/connectionmanager/callback/PrepareForConnection.java | Java | asf20 | 2,826 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.connectionmanager.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.controlpoint.ControlPoint;
import org.teleal.cling.model.action.ActionArgumentValue;
import org.teleal.cling.model.action.ActionException;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.ErrorCode;
import org.teleal.cling.support.model.ProtocolInfos;
/**
* @author Christian Bauer
*/
public abstract class GetProtocolInfo extends ActionCallback {
public GetProtocolInfo(Service service) {
this(service, null);
}
protected GetProtocolInfo(Service service, ControlPoint controlPoint) {
super(new ActionInvocation(service.getAction("GetProtocolInfo")), controlPoint);
}
@Override
public void success(ActionInvocation invocation) {
try {
ActionArgumentValue sink = invocation.getOutput("Sink");
ActionArgumentValue source = invocation.getOutput("Source");
received(
invocation,
sink != null ? new ProtocolInfos(sink.toString()) : null,
source != null ? new ProtocolInfos(source.toString()) : null
);
} catch (Exception ex) {
invocation.setFailure(
new ActionException(ErrorCode.ACTION_FAILED, "Can't parse ProtocolInfo response: " + ex, ex)
);
failure(invocation, null);
}
}
public abstract void received(ActionInvocation actionInvocation, ProtocolInfos sinkProtocolInfos, ProtocolInfos sourceProtocolInfos);
} | zzh84615-mycode | src/org/teleal/cling/support/connectionmanager/callback/GetProtocolInfo.java | Java | asf20 | 2,403 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.connectionmanager;
import org.teleal.cling.binding.annotations.UpnpAction;
import org.teleal.cling.binding.annotations.UpnpInputArgument;
import org.teleal.cling.binding.annotations.UpnpOutputArgument;
import org.teleal.cling.controlpoint.ControlPoint;
import org.teleal.cling.model.ServiceReference;
import org.teleal.cling.model.action.ActionException;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.message.UpnpResponse;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.ErrorCode;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.model.types.csv.CSV;
import org.teleal.cling.support.connectionmanager.callback.ConnectionComplete;
import org.teleal.cling.support.connectionmanager.callback.PrepareForConnection;
import org.teleal.cling.support.model.ConnectionInfo;
import org.teleal.cling.support.model.ProtocolInfo;
import org.teleal.cling.support.model.ProtocolInfos;
import java.beans.PropertyChangeSupport;
import java.util.logging.Logger;
/**
* Support for setup and teardown of an arbitrary number of connections with a manager peer.
*
* @author Christian Bauer
* @author Alessio Gaeta
*/
public abstract class AbstractPeeringConnectionManagerService extends ConnectionManagerService {
final private static Logger log = Logger.getLogger(AbstractPeeringConnectionManagerService.class.getName());
protected AbstractPeeringConnectionManagerService(ConnectionInfo... activeConnections) {
super(activeConnections);
}
protected AbstractPeeringConnectionManagerService(ProtocolInfos sourceProtocolInfo, ProtocolInfos sinkProtocolInfo,
ConnectionInfo... activeConnections) {
super(sourceProtocolInfo, sinkProtocolInfo, activeConnections);
}
protected AbstractPeeringConnectionManagerService(PropertyChangeSupport propertyChangeSupport,
ProtocolInfos sourceProtocolInfo, ProtocolInfos sinkProtocolInfo,
ConnectionInfo... activeConnections) {
super(propertyChangeSupport, sourceProtocolInfo, sinkProtocolInfo, activeConnections);
}
synchronized protected int getNewConnectionId() {
int currentHighestID = -1;
for (Integer key : activeConnections.keySet()) {
if (key > currentHighestID) currentHighestID = key;
}
return ++currentHighestID;
}
synchronized protected void storeConnection(ConnectionInfo info) {
CSV<UnsignedIntegerFourBytes> oldConnectionIDs = getCurrentConnectionIDs();
activeConnections.put(info.getConnectionID(), info);
log.fine("Connection stored, firing event: " + info.getConnectionID());
CSV<UnsignedIntegerFourBytes> newConnectionIDs = getCurrentConnectionIDs();
getPropertyChangeSupport().firePropertyChange("CurrentConnectionIDs", oldConnectionIDs, newConnectionIDs);
}
synchronized protected void removeConnection(int connectionID) {
CSV<UnsignedIntegerFourBytes> oldConnectionIDs = getCurrentConnectionIDs();
activeConnections.remove(connectionID);
log.fine("Connection removed, firing event: " + connectionID);
CSV<UnsignedIntegerFourBytes> newConnectionIDs = getCurrentConnectionIDs();
getPropertyChangeSupport().firePropertyChange("CurrentConnectionIDs", oldConnectionIDs, newConnectionIDs);
}
@UpnpAction(out = {
@UpnpOutputArgument(name = "ConnectionID", stateVariable = "A_ARG_TYPE_ConnectionID", getterName = "getConnectionID"),
@UpnpOutputArgument(name = "AVTransportID", stateVariable = "A_ARG_TYPE_AVTransportID", getterName = "getAvTransportID"),
@UpnpOutputArgument(name = "RcsID", stateVariable = "A_ARG_TYPE_RcsID", getterName = "getRcsID")
})
synchronized public ConnectionInfo prepareForConnection(
@UpnpInputArgument(name = "RemoteProtocolInfo", stateVariable = "A_ARG_TYPE_ProtocolInfo") ProtocolInfo remoteProtocolInfo,
@UpnpInputArgument(name = "PeerConnectionManager", stateVariable = "A_ARG_TYPE_ConnectionManager") ServiceReference peerConnectionManager,
@UpnpInputArgument(name = "PeerConnectionID", stateVariable = "A_ARG_TYPE_ConnectionID") int peerConnectionId,
@UpnpInputArgument(name = "Direction", stateVariable = "A_ARG_TYPE_Direction") String direction)
throws ActionException {
int connectionId = getNewConnectionId();
ConnectionInfo.Direction dir;
try {
dir = ConnectionInfo.Direction.valueOf(direction);
} catch (Exception ex) {
throw new ConnectionManagerException(ErrorCode.ARGUMENT_VALUE_INVALID, "Unsupported direction: " + direction);
}
log.fine("Preparing for connection with local new ID " + connectionId + " and peer connection ID: " + peerConnectionId);
ConnectionInfo newConnectionInfo = createConnection(
connectionId,
peerConnectionId,
peerConnectionManager,
dir,
remoteProtocolInfo
);
storeConnection(newConnectionInfo);
return newConnectionInfo;
}
@UpnpAction
synchronized public void connectionComplete(@UpnpInputArgument(name = "ConnectionID", stateVariable = "A_ARG_TYPE_ConnectionID") int connectionID)
throws ActionException {
ConnectionInfo info = getCurrentConnectionInfo(connectionID);
log.fine("Closing connection ID " + connectionID);
closeConnection(info);
removeConnection(connectionID);
}
/**
* Generate a new local connection identifier, prepare the peer, store connection details.
*
* @return <code>-1</code> if the {@link #peerFailure(org.teleal.cling.model.action.ActionInvocation, org.teleal.cling.model.message.UpnpResponse, String)}
* method had to be called, otherwise the local identifier of the established connection.
*/
synchronized public int createConnectionWithPeer(final ServiceReference localServiceReference,
final ControlPoint controlPoint,
final Service peerService,
final ProtocolInfo protInfo,
final ConnectionInfo.Direction direction) {
// It is important that you synchronize the whole procedure, starting with getNewConnectionID(),
// then preparing the connection on the peer, then storeConnection()
final int localConnectionID = getNewConnectionId();
log.fine("Creating new connection ID " + localConnectionID + " with peer: " + peerService);
final boolean[] failed = new boolean[1];
new PrepareForConnection(
peerService,
controlPoint,
protInfo,
localServiceReference,
localConnectionID,
direction
) {
@Override
public void received(ActionInvocation invocation, int peerConnectionID, int rcsID, int avTransportID) {
ConnectionInfo info = new ConnectionInfo(
localConnectionID,
rcsID,
avTransportID,
protInfo,
peerService.getReference(),
peerConnectionID,
direction.getOpposite(), // If I prepared you for output, then I do input
ConnectionInfo.Status.OK
);
storeConnection(info);
}
@Override
public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
AbstractPeeringConnectionManagerService.this.peerFailure(
invocation, operation, defaultMsg
);
failed[0] = true;
}
}.run(); // Synchronous execution! We "reserved" a new connection ID earlier!
return failed[0] ? -1 : localConnectionID;
}
/**
* Close the connection with the peer, remove the connection details.
*/
synchronized public void closeConnectionWithPeer(ControlPoint controlPoint,
Service peerService,
int connectionID) throws ActionException {
closeConnectionWithPeer(controlPoint, peerService, getCurrentConnectionInfo(connectionID));
}
/**
* Close the connection with the peer, remove the connection details.
*/
synchronized public void closeConnectionWithPeer(final ControlPoint controlPoint,
final Service peerService,
final ConnectionInfo connectionInfo) throws ActionException {
// It is important that you synchronize the whole procedure
log.fine("Closing connection ID " + connectionInfo.getConnectionID() + " with peer: " + peerService);
new ConnectionComplete(
peerService,
controlPoint,
connectionInfo.getPeerConnectionID()
) {
@Override
public void success(ActionInvocation invocation) {
removeConnection(connectionInfo.getConnectionID());
}
@Override
public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
AbstractPeeringConnectionManagerService.this.peerFailure(
invocation, operation, defaultMsg
);
}
}.run(); // Synchronous execution!
}
protected abstract ConnectionInfo createConnection(int connectionID,
int peerConnectionId, ServiceReference peerConnectionManager,
ConnectionInfo.Direction direction, ProtocolInfo protocolInfo) throws ActionException;
protected abstract void closeConnection(ConnectionInfo connectionInfo);
/**
* Called when connection creation or closing with a peer failed.
* <p>
* This is the failure result of an action invocation on the peer's connection
* management service. The execution of the {@link #createConnectionWithPeer(org.teleal.cling.model.ServiceReference, org.teleal.cling.controlpoint.ControlPoint, org.teleal.cling.model.meta.Service, org.teleal.cling.support.model.ProtocolInfo , org.teleal.cling.support.model.ConnectionInfo.Direction)}
* and {@link #closeConnectionWithPeer(org.teleal.cling.controlpoint.ControlPoint, org.teleal.cling.model.meta.Service, org.teleal.cling.support.model.ConnectionInfo)}
* methods will block until this method completes handling any failure.
* </p>
*
* @param invocation The underlying action invocation of the remote connection manager service.
* @param operation The network message response if there was a response, or <code>null</code>.
* @param defaultFailureMessage A user-friendly error message generated from the invocation exception and response.
*/
protected abstract void peerFailure(ActionInvocation invocation, UpnpResponse operation, String defaultFailureMessage);
}
| zzh84615-mycode | src/org/teleal/cling/support/connectionmanager/AbstractPeeringConnectionManagerService.java | Java | asf20 | 12,332 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.connectionmanager;
/**
*
*/
public enum ConnectionManagerErrorCode {
INCOMPATIBLE_PROTOCOL_INFO(701, "The connection cannot be established because the protocol info parameter is incompatible"),
INCOMPATIBLE_DIRECTIONS(702, "The connection cannot be established because the directions of the involved ConnectionManagers (source/sink) are incompatible"),
INSUFFICIENT_NETWORK_RESOURCES(703, "The connection cannot be established because there are insufficient network resources"),
LOCAL_RESTRICTIONS(704, "The connection cannot be established because of local restrictions in the device"),
ACCESS_DENIED(705, "The connection cannot be established because the client is not permitted."),
INVALID_CONNECTION_REFERENCE(706, "Not a valid connection established by this service"),
NOT_IN_NETWORK(707, "The connection cannot be established because the ConnectionManagers are not part of the same physical network.");
private int code;
private String description;
ConnectionManagerErrorCode(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static ConnectionManagerErrorCode getByCode(int code) {
for (ConnectionManagerErrorCode errorCode : ConnectionManagerErrorCode.values()) {
if (errorCode.getCode() == code)
return errorCode;
}
return null;
}
} | zzh84615-mycode | src/org/teleal/cling/support/connectionmanager/ConnectionManagerErrorCode.java | Java | asf20 | 2,294 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.contentdirectory;
import org.teleal.cling.binding.annotations.UpnpAction;
import org.teleal.cling.binding.annotations.UpnpInputArgument;
import org.teleal.cling.binding.annotations.UpnpOutputArgument;
import org.teleal.cling.binding.annotations.UpnpService;
import org.teleal.cling.binding.annotations.UpnpServiceId;
import org.teleal.cling.binding.annotations.UpnpServiceType;
import org.teleal.cling.binding.annotations.UpnpStateVariable;
import org.teleal.cling.binding.annotations.UpnpStateVariables;
import org.teleal.cling.model.types.ErrorCode;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.model.types.csv.CSV;
import org.teleal.cling.model.types.csv.CSVString;
import org.teleal.cling.support.model.BrowseFlag;
import org.teleal.cling.support.model.BrowseResult;
import org.teleal.cling.support.model.DIDLContent;
import org.teleal.cling.support.model.SortCriterion;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;
/**
* Simple ContentDirectory service skeleton.
* <p>
* Only state variables and actions required by <em>ContentDirectory:1</em>
* (not the optional ones) are implemented.
* </p>
*
* @author Alessio Gaeta
* @author Christian Bauer
*/
@UpnpService(
serviceId = @UpnpServiceId("ContentDirectory"),
serviceType = @UpnpServiceType(value = "ContentDirectory", version = 1)
)
@UpnpStateVariables({
@UpnpStateVariable(
name = "A_ARG_TYPE_ObjectID",
sendEvents = false,
datatype = "string"),
@UpnpStateVariable(
name = "A_ARG_TYPE_Result",
sendEvents = false,
datatype = "string"),
@UpnpStateVariable(
name = "A_ARG_TYPE_BrowseFlag",
sendEvents = false,
datatype = "string",
allowedValuesEnum = BrowseFlag.class),
@UpnpStateVariable(
name = "A_ARG_TYPE_Filter",
sendEvents = false,
datatype = "string"),
@UpnpStateVariable(
name = "A_ARG_TYPE_SortCriteria",
sendEvents = false,
datatype = "string"),
@UpnpStateVariable(
name = "A_ARG_TYPE_Index",
sendEvents = false,
datatype = "ui4"),
@UpnpStateVariable(
name = "A_ARG_TYPE_Count",
sendEvents = false,
datatype = "ui4"),
@UpnpStateVariable(
name = "A_ARG_TYPE_UpdateID",
sendEvents = false,
datatype = "ui4"),
@UpnpStateVariable(
name = "A_ARG_TYPE_URI",
sendEvents = false,
datatype = "uri"),
@UpnpStateVariable(
name = "A_ARG_TYPE_SearchCriteria",
sendEvents = false,
datatype = "string")
})
public abstract class AbstractContentDirectoryService {
public static final String CAPS_WILDCARD = "*";
@UpnpStateVariable(sendEvents = false)
final private CSV<String> searchCapabilities;
@UpnpStateVariable(sendEvents = false)
final private CSV<String> sortCapabilities;
@UpnpStateVariable(
sendEvents = true,
defaultValue = "0",
eventMaximumRateMilliseconds = 200
)
private UnsignedIntegerFourBytes systemUpdateID = new UnsignedIntegerFourBytes(0);
final protected PropertyChangeSupport propertyChangeSupport;
protected AbstractContentDirectoryService() {
this(new ArrayList(), new ArrayList(), null);
}
protected AbstractContentDirectoryService(List<String> searchCapabilities, List<String> sortCapabilities) {
this(searchCapabilities, sortCapabilities, null);
}
protected AbstractContentDirectoryService(List<String> searchCapabilities, List<String> sortCapabilities,
PropertyChangeSupport propertyChangeSupport) {
this.propertyChangeSupport = propertyChangeSupport != null ? propertyChangeSupport : new PropertyChangeSupport(this);
this.searchCapabilities = new CSVString();
this.searchCapabilities.addAll(searchCapabilities);
this.sortCapabilities = new CSVString();
this.sortCapabilities.addAll(sortCapabilities);
}
@UpnpAction(out = @UpnpOutputArgument(name = "SearchCaps"))
public CSV<String> getSearchCapabilities() {
return searchCapabilities;
}
@UpnpAction(out = @UpnpOutputArgument(name = "SortCaps"))
public CSV<String> getSortCapabilities() {
return sortCapabilities;
}
@UpnpAction(out = @UpnpOutputArgument(name = "Id"))
synchronized public UnsignedIntegerFourBytes getSystemUpdateID() {
return systemUpdateID;
}
public PropertyChangeSupport getPropertyChangeSupport() {
return propertyChangeSupport;
}
/**
* Call this method after making changes to your content directory.
* <p>
* This will notify clients that their view of the content directory is potentially
* outdated and has to be refreshed.
* </p>
*/
synchronized protected void changeSystemUpdateID() {
Long oldUpdateID = getSystemUpdateID().getValue();
systemUpdateID.increment(true);
getPropertyChangeSupport().firePropertyChange(
"SystemUpdateID",
oldUpdateID,
getSystemUpdateID().getValue()
);
}
@UpnpAction(out = {
@UpnpOutputArgument(name = "Result",
stateVariable = "A_ARG_TYPE_Result",
getterName = "getResult"),
@UpnpOutputArgument(name = "NumberReturned",
stateVariable = "A_ARG_TYPE_Count",
getterName = "getCount"),
@UpnpOutputArgument(name = "TotalMatches",
stateVariable = "A_ARG_TYPE_Count",
getterName = "getTotalMatches"),
@UpnpOutputArgument(name = "UpdateID",
stateVariable = "A_ARG_TYPE_UpdateID",
getterName = "getContainerUpdateID")
})
public BrowseResult browse(
@UpnpInputArgument(name = "ObjectID", aliases = "ContainerID") String objectId,
@UpnpInputArgument(name = "BrowseFlag") String browseFlag,
@UpnpInputArgument(name = "Filter") String filter,
@UpnpInputArgument(name = "StartingIndex", stateVariable = "A_ARG_TYPE_Index") UnsignedIntegerFourBytes firstResult,
@UpnpInputArgument(name = "RequestedCount", stateVariable = "A_ARG_TYPE_Count") UnsignedIntegerFourBytes maxResults,
@UpnpInputArgument(name = "SortCriteria") String orderBy)
throws ContentDirectoryException {
SortCriterion[] orderByCriteria;
try {
orderByCriteria = SortCriterion.valueOf(orderBy);
} catch (Exception ex) {
throw new ContentDirectoryException(ContentDirectoryErrorCode.UNSUPPORTED_SORT_CRITERIA, ex.toString());
}
try {
return browse(
objectId,
BrowseFlag.valueOrNullOf(browseFlag),
filter,
firstResult.getValue(), maxResults.getValue(),
orderByCriteria
);
} catch (ContentDirectoryException ex) {
throw ex;
} catch (Exception ex) {
throw new ContentDirectoryException(ErrorCode.ACTION_FAILED, ex.toString());
}
}
/**
* Implement this method to implement browsing of your content.
* <p>
* This is a required action defined by <em>ContentDirectory:1</em>.
* </p>
* <p>
* You should wrap any exception into a {@link ContentDirectoryException}, so a propery
* error message can be returned to control points.
* </p>
*/
public abstract BrowseResult browse(String objectID, BrowseFlag browseFlag,
String filter,
long firstResult, long maxResults,
SortCriterion[] orderby) throws ContentDirectoryException;
@UpnpAction(out = {
@UpnpOutputArgument(name = "Result",
stateVariable = "A_ARG_TYPE_Result",
getterName = "getResult"),
@UpnpOutputArgument(name = "NumberReturned",
stateVariable = "A_ARG_TYPE_Count",
getterName = "getCount"),
@UpnpOutputArgument(name = "TotalMatches",
stateVariable = "A_ARG_TYPE_Count",
getterName = "getTotalMatches"),
@UpnpOutputArgument(name = "UpdateID",
stateVariable = "A_ARG_TYPE_UpdateID",
getterName = "getContainerUpdateID")
})
public BrowseResult search(
@UpnpInputArgument(name = "ContainerID", stateVariable = "A_ARG_TYPE_ObjectID") String containerId,
@UpnpInputArgument(name = "SearchCriteria") String searchCriteria,
@UpnpInputArgument(name = "Filter") String filter,
@UpnpInputArgument(name = "StartingIndex", stateVariable = "A_ARG_TYPE_Index") UnsignedIntegerFourBytes firstResult,
@UpnpInputArgument(name = "RequestedCount", stateVariable = "A_ARG_TYPE_Count") UnsignedIntegerFourBytes maxResults,
@UpnpInputArgument(name = "SortCriteria") String orderBy)
throws ContentDirectoryException {
SortCriterion[] orderByCriteria;
try {
orderByCriteria = SortCriterion.valueOf(orderBy);
} catch (Exception ex) {
throw new ContentDirectoryException(ContentDirectoryErrorCode.UNSUPPORTED_SORT_CRITERIA, ex.toString());
}
try {
return search(
containerId,
searchCriteria,
filter,
firstResult.getValue(), maxResults.getValue(),
orderByCriteria
);
} catch (ContentDirectoryException ex) {
throw ex;
} catch (Exception ex) {
throw new ContentDirectoryException(ErrorCode.ACTION_FAILED, ex.toString());
}
}
/**
* Override this method to implement searching of your content.
* <p>
* The default implementation returns an empty result.
* </p>
*/
public BrowseResult search(String containerId, String searchCriteria, String filter,
long firstResult, long maxResults, SortCriterion[] orderBy) throws ContentDirectoryException {
try {
return new BrowseResult(new DIDLParser().generate(new DIDLContent()), 0, 0);
} catch (Exception ex) {
throw new ContentDirectoryException(ErrorCode.ACTION_FAILED, ex.toString());
}
}
}
| zzh84615-mycode | src/org/teleal/cling/support/contentdirectory/AbstractContentDirectoryService.java | Java | asf20 | 12,763 |
/*
* Copyright (C) 2011 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.contentdirectory;
import org.teleal.cling.model.types.Datatype;
import org.teleal.cling.model.types.InvalidValueException;
import org.teleal.cling.support.model.DIDLAttribute;
import org.teleal.cling.support.model.DIDLContent;
import org.teleal.cling.support.model.DIDLObject;
import org.teleal.cling.support.model.DescMeta;
import org.teleal.cling.support.model.Person;
import org.teleal.cling.support.model.PersonWithRole;
import org.teleal.cling.support.model.ProtocolInfo;
import org.teleal.cling.support.model.Res;
import org.teleal.cling.support.model.StorageMedium;
import org.teleal.cling.support.model.WriteStatus;
import org.teleal.cling.support.model.container.Container;
import org.teleal.cling.support.model.item.Item;
import org.teleal.common.io.IO;
import org.teleal.common.util.Exceptions;
import org.teleal.common.xml.SAXParser;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.teleal.cling.model.XMLUtil.appendNewElement;
import static org.teleal.cling.model.XMLUtil.appendNewElementIfNotNull;
/**
* DIDL parser based on SAX for reading and DOM for writing.
* <p>
* This parser requires Android platform level 8 (2.2).
* </p>
* <p>
* Override the {@link #createDescMetaHandler(org.teleal.cling.support.model.DescMeta, org.teleal.common.xml.SAXParser.Handler)}
* method to read vendor extension content of {@code <desc>} elements. You then should also override the
* {@link #populateDescMetadata(org.w3c.dom.Element, org.teleal.cling.support.model.DescMeta)} method for writing.
* </p>
* <p>
* Override the {@link #createItemHandler(org.teleal.cling.support.model.item.Item, org.teleal.common.xml.SAXParser.Handler)}
* etc. methods to register custom handlers for vendor-specific elements and attributes within items, containers,
* and so on.
* </p>
*
* @author Christian Bauer
* @author Mario Franco
*/
public class DIDLParser extends SAXParser {
final private static Logger log = Logger.getLogger(DIDLParser.class.getName());
/**
* Uses the current thread's context classloader to read and unmarshall the given resource.
*
* @param resource The resource on the classpath.
* @return The unmarshalled DIDL content model.
* @throws Exception
*/
public DIDLContent parseResource(String resource) throws Exception {
InputStream is = null;
try {
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
return parse(IO.readLines(is));
} finally {
if (is != null) is.close();
}
}
/**
* Reads and unmarshalls an XML representation into a DIDL content model.
*
* @param xml The XML representation.
* @return A DIDL content model.
* @throws Exception
*/
public DIDLContent parse(String xml) throws Exception {
if (xml == null || xml.length() == 0) {
throw new RuntimeException("Null or empty XML");
}
DIDLContent content = new DIDLContent();
createRootHandler(content, this);
log.fine("Parsing DIDL XML content");
parse(new InputSource(new StringReader(xml)));
return content;
}
protected RootHandler createRootHandler(DIDLContent instance, SAXParser parser) {
return new RootHandler(instance, parser);
}
protected ContainerHandler createContainerHandler(Container instance, Handler parent) {
return new ContainerHandler(instance, parent);
}
protected ItemHandler createItemHandler(Item instance, Handler parent) {
return new ItemHandler(instance, parent);
}
protected ResHandler createResHandler(Res instance, Handler parent) {
return new ResHandler(instance, parent);
}
protected DescMetaHandler createDescMetaHandler(DescMeta instance, Handler parent) {
return new DescMetaHandler(instance, parent);
}
protected Container createContainer(Attributes attributes) {
Container container = new Container();
container.setId(attributes.getValue("id"));
container.setParentID(attributes.getValue("parentID"));
if ((attributes.getValue("childCount") != null))
container.setChildCount(Integer.valueOf(attributes.getValue("childCount")));
try {
Boolean value = (Boolean)Datatype.Builtin.BOOLEAN.getDatatype().valueOf(
attributes.getValue("restricted")
);
if (value != null)
container.setRestricted(value);
value = (Boolean)Datatype.Builtin.BOOLEAN.getDatatype().valueOf(
attributes.getValue("searchable")
);
if (value != null)
container.setSearchable(value);
} catch (Exception ex) {
// Ignore
}
return container;
}
protected Item createItem(Attributes attributes) {
Item item = new Item();
item.setId(attributes.getValue("id"));
item.setParentID(attributes.getValue("parentID"));
try {
Boolean value = (Boolean)Datatype.Builtin.BOOLEAN.getDatatype().valueOf(
attributes.getValue("restricted")
);
if (value != null)
item.setRestricted(value);
} catch (Exception ex) {
// Ignore
}
if ((attributes.getValue("refID") != null))
item.setRefID(attributes.getValue("refID"));
return item;
}
protected Res createResource(Attributes attributes) {
Res res = new Res();
if (attributes.getValue("importUri") != null)
res.setImportUri(URI.create(attributes.getValue("importUri")));
try {
res.setProtocolInfo(
new ProtocolInfo(attributes.getValue("protocolInfo"))
);
} catch (InvalidValueException ex) {
log.warning("In DIDL content, invalid resource protocol info: " + Exceptions.unwrap(ex));
return null;
}
if (attributes.getValue("size") != null)
res.setSize(Long.valueOf(attributes.getValue("size")));
if (attributes.getValue("duration") != null)
res.setDuration(attributes.getValue("duration"));
if (attributes.getValue("bitrate") != null)
res.setBitrate(Long.valueOf(attributes.getValue("bitrate")));
if (attributes.getValue("sampleFrequency") != null)
res.setSampleFrequency(Long.valueOf(attributes.getValue("sampleFrequency")));
if (attributes.getValue("bitsPerSample") != null)
res.setBitsPerSample(Long.valueOf(attributes.getValue("bitsPerSample")));
if (attributes.getValue("nrAudioChannels") != null)
res.setNrAudioChannels(Long.valueOf(attributes.getValue("nrAudioChannels")));
if (attributes.getValue("colorDepth") != null)
res.setColorDepth(Long.valueOf(attributes.getValue("colorDepth")));
if (attributes.getValue("protection") != null)
res.setProtection(attributes.getValue("protection"));
if (attributes.getValue("resolution") != null)
res.setResolution(attributes.getValue("resolution"));
return res;
}
protected DescMeta createDescMeta(Attributes attributes) {
DescMeta desc = new DescMeta();
desc.setId(attributes.getValue("id"));
if ((attributes.getValue("type") != null))
desc.setType(attributes.getValue("type"));
if ((attributes.getValue("nameSpace") != null))
desc.setNameSpace(URI.create(attributes.getValue("nameSpace")));
return desc;
}
/* ############################################################################################# */
/**
* Generates a XML representation of the content model.
* <p>
* Items inside a container will <em>not</em> be represented in the XML, the containers
* will be rendered flat without children.
* </p>
*
* @param content The content model.
* @return An XML representation.
* @throws Exception
*/
public String generate(DIDLContent content) throws Exception {
return generate(content, false);
}
/**
* Generates an XML representation of the content model.
* <p>
* Optionally, items inside a container will be represented in the XML,
* the container elements then have nested item elements. Although this
* parser can read such a structure, it is unclear whether other DIDL
* parsers should and actually do support this XML.
* </p>
*
* @param content The content model.
* @param nestedItems <code>true</code> if nested item elements should be rendered for containers.
* @return An XML representation.
* @throws Exception
*/
public String generate(DIDLContent content, boolean nestedItems) throws Exception {
return documentToString(buildDOM(content, nestedItems), true);
}
// TODO: Yes, this only runs on Android 2.2
protected String documentToString(Document document, boolean omitProlog) throws Exception {
TransformerFactory transFactory = TransformerFactory.newInstance();
// Indentation not supported on Android 2.2
//transFactory.setAttribute("indent-number", 4);
Transformer transformer = transFactory.newTransformer();
if (omitProlog) {
// TODO: UPNP VIOLATION: Terratec Noxon Webradio fails when DIDL content has a prolog
// No XML prolog! This is allowed because it is UTF-8 encoded and required
// because broken devices will stumble on SOAP messages that contain (even
// encoded) XML prologs within a message body.
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
}
// Again, Android 2.2 fails hard if you try this.
//transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StringWriter out = new StringWriter();
transformer.transform(new DOMSource(document), new StreamResult(out));
return out.toString();
}
protected Document buildDOM(DIDLContent content, boolean nestedItems) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document d = factory.newDocumentBuilder().newDocument();
generateRoot(content, d, nestedItems);
return d;
}
protected void generateRoot(DIDLContent content, Document descriptor, boolean nestedItems) {
Element rootElement = descriptor.createElementNS(DIDLContent.NAMESPACE_URI, "DIDL-Lite");
descriptor.appendChild(rootElement);
// rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:didl", DIDLContent.NAMESPACE_URI);
rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:upnp", DIDLObject.Property.UPNP.NAMESPACE.URI);
rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:dc", DIDLObject.Property.DC.NAMESPACE.URI);
for (Container container : content.getContainers()) {
if (container == null) continue;
generateContainer(container, descriptor, rootElement, nestedItems);
}
for (Item item : content.getItems()) {
if (item == null) continue;
generateItem(item, descriptor, rootElement);
}
for (DescMeta descMeta : content.getDescMetadata()) {
if (descMeta == null) continue;
generateDescMetadata(descMeta, descriptor, rootElement);
}
}
protected void generateContainer(Container container, Document descriptor, Element parent, boolean nestedItems) {
if (container.getTitle() == null) {
throw new RuntimeException("Missing 'dc:title' element for container: " + container.getId());
}
if (container.getClazz() == null) {
throw new RuntimeException("Missing 'upnp:class' element for container: " + container.getId());
}
Element containerElement = appendNewElement(descriptor, parent, "container");
if (container.getId() == null)
throw new NullPointerException("Missing id on container: " + container);
containerElement.setAttribute("id", container.getId());
if (container.getParentID() == null)
throw new NullPointerException("Missing parent id on container: " + container);
containerElement.setAttribute("parentID", container.getParentID());
if (container.getChildCount() != null) {
containerElement.setAttribute("childCount", Integer.toString(container.getChildCount()));
}
containerElement.setAttribute("restricted", Boolean.toString(container.isRestricted()));
containerElement.setAttribute("searchable", Boolean.toString(container.isSearchable()));
appendNewElementIfNotNull(
descriptor,
containerElement,
"dc:title",
container.getTitle(),
DIDLObject.Property.DC.NAMESPACE.URI
);
appendNewElementIfNotNull(
descriptor,
containerElement,
"dc:creator",
container.getCreator(),
DIDLObject.Property.DC.NAMESPACE.URI
);
appendNewElementIfNotNull(
descriptor,
containerElement,
"upnp:writeStatus",
container.getWriteStatus(),
DIDLObject.Property.UPNP.NAMESPACE.URI
);
appendClass(descriptor, containerElement, container.getClazz(), "upnp:class", false);
for (DIDLObject.Class searchClass : container.getSearchClasses()) {
appendClass(descriptor, containerElement, searchClass, "upnp:searchClass", true);
}
for (DIDLObject.Class createClass : container.getCreateClasses()) {
appendClass(descriptor, containerElement, createClass, "upnp:createClass", true);
}
appendProperties(descriptor, containerElement, container, "upnp", DIDLObject.Property.UPNP.NAMESPACE.class, DIDLObject.Property.UPNP.NAMESPACE.URI);
appendProperties(descriptor, containerElement, container, "dc", DIDLObject.Property.DC.NAMESPACE.class, DIDLObject.Property.DC.NAMESPACE.URI);
if (nestedItems) {
for (Item item : container.getItems()) {
if (item == null) continue;
generateItem(item, descriptor, containerElement);
}
}
for (Res resource : container.getResources()) {
if (resource == null) continue;
generateResource(resource, descriptor, containerElement);
}
for (DescMeta descMeta : container.getDescMetadata()) {
if (descMeta == null) continue;
generateDescMetadata(descMeta, descriptor, containerElement);
}
}
protected void generateItem(Item item, Document descriptor, Element parent) {
if (item.getTitle() == null) {
throw new RuntimeException("Missing 'dc:title' element for item: " + item.getId());
}
if (item.getClazz() == null) {
throw new RuntimeException("Missing 'upnp:class' element for item: " + item.getId());
}
Element itemElement = appendNewElement(descriptor, parent, "item");
if (item.getId() == null)
throw new NullPointerException("Missing id on item: " + item);
itemElement.setAttribute("id", item.getId());
if (item.getParentID() == null)
throw new NullPointerException("Missing parent id on item: " + item);
itemElement.setAttribute("parentID", item.getParentID());
if (item.getRefID() != null)
itemElement.setAttribute("refID", item.getRefID());
itemElement.setAttribute("restricted", Boolean.toString(item.isRestricted()));
appendNewElementIfNotNull(
descriptor,
itemElement,
"dc:title",
item.getTitle(),
DIDLObject.Property.DC.NAMESPACE.URI
);
appendNewElementIfNotNull(
descriptor,
itemElement,
"dc:creator",
item.getCreator(),
DIDLObject.Property.DC.NAMESPACE.URI
);
appendNewElementIfNotNull(
descriptor,
itemElement,
"upnp:writeStatus",
item.getWriteStatus(),
DIDLObject.Property.UPNP.NAMESPACE.URI
);
appendClass(descriptor, itemElement, item.getClazz(), "upnp:class", false);
appendProperties(descriptor, itemElement, item, "upnp", DIDLObject.Property.UPNP.NAMESPACE.class, DIDLObject.Property.UPNP.NAMESPACE.URI);
appendProperties(descriptor, itemElement, item, "dc", DIDLObject.Property.DC.NAMESPACE.class, DIDLObject.Property.DC.NAMESPACE.URI);
for (Res resource : item.getResources()) {
if (resource == null) continue;
generateResource(resource, descriptor, itemElement);
}
for (DescMeta descMeta : item.getDescMetadata()) {
if (descMeta == null) continue;
generateDescMetadata(descMeta, descriptor, itemElement);
}
}
protected void generateResource(Res resource, Document descriptor, Element parent) {
if (resource.getValue() == null) {
throw new RuntimeException("Missing resource URI value" + resource);
}
if (resource.getProtocolInfo() == null) {
throw new RuntimeException("Missing resource protocol info: " + resource);
}
Element resourceElement = appendNewElement(descriptor, parent, "res", resource.getValue());
resourceElement.setAttribute("protocolInfo", resource.getProtocolInfo().toString());
if (resource.getImportUri() != null)
resourceElement.setAttribute("importUri", resource.getImportUri().toString());
if (resource.getSize() != null)
resourceElement.setAttribute("size", resource.getSize().toString());
if (resource.getDuration() != null)
resourceElement.setAttribute("duration", resource.getDuration());
if (resource.getBitrate() != null)
resourceElement.setAttribute("bitrate", resource.getBitrate().toString());
if (resource.getSampleFrequency() != null)
resourceElement.setAttribute("sampleFrequency", resource.getSampleFrequency().toString());
if (resource.getBitsPerSample() != null)
resourceElement.setAttribute("bitsPerSample", resource.getBitsPerSample().toString());
if (resource.getNrAudioChannels() != null)
resourceElement.setAttribute("nrAudioChannels", resource.getNrAudioChannels().toString());
if (resource.getColorDepth() != null)
resourceElement.setAttribute("colorDepth", resource.getColorDepth().toString());
if (resource.getProtection() != null)
resourceElement.setAttribute("protection", resource.getProtection());
if (resource.getResolution() != null)
resourceElement.setAttribute("resolution", resource.getResolution());
}
protected void generateDescMetadata(DescMeta descMeta, Document descriptor, Element parent) {
if (descMeta.getId() == null) {
throw new RuntimeException("Missing id of description metadata: " + descMeta);
}
if (descMeta.getNameSpace() == null) {
throw new RuntimeException("Missing namespace of description metadata: " + descMeta);
}
Element descElement = appendNewElement(descriptor, parent, "desc");
descElement.setAttribute("id", descMeta.getId());
descElement.setAttribute("nameSpace", descMeta.getNameSpace().toString());
if (descMeta.getType() != null)
descElement.setAttribute("type", descMeta.getType());
populateDescMetadata(descElement, descMeta);
}
/**
* Expects an <code>org.w3c.Document</code> as metadata, copies nodes of the document into the DIDL content.
* <p>
* This method will ignore the content and log a warning if it's of the wrong type. If you override
* {@link #createDescMetaHandler(org.teleal.cling.support.model.DescMeta, org.teleal.common.xml.SAXParser.Handler)},
* you most likely also want to override this method.
* </p>
*
* @param descElement The DIDL content {@code <desc>} element wrapping the final metadata.
* @param descMeta The metadata with a <code>org.w3c.Document</code> payload.
*/
protected void populateDescMetadata(Element descElement, DescMeta descMeta) {
if (descMeta.getMetadata() instanceof Document) {
Document doc = (Document) descMeta.getMetadata();
NodeList nl = doc.getDocumentElement().getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i);
if (n.getNodeType() != Node.ELEMENT_NODE)
continue;
Node clone = descElement.getOwnerDocument().importNode(n, true);
descElement.appendChild(clone);
}
} else {
log.warning("Unknown desc metadata content, please override populateDescMetadata(): " + descMeta.getMetadata());
}
}
protected void appendProperties(Document descriptor, Element parent, DIDLObject object, String prefix,
Class<? extends DIDLObject.Property.NAMESPACE> namespace,
String namespaceURI) {
for (DIDLObject.Property<Object> property : object.getPropertiesByNamespace(namespace)) {
Element el = descriptor.createElementNS(namespaceURI, prefix + ":" + property.getDescriptorName());
parent.appendChild(el);
property.setOnElement(el);
}
}
protected void appendClass(Document descriptor, Element parent, DIDLObject.Class clazz, String element, boolean appendDerivation) {
Element classElement = appendNewElementIfNotNull(
descriptor,
parent,
element,
clazz.getValue(),
DIDLObject.Property.UPNP.NAMESPACE.URI
);
if (clazz.getFriendlyName() != null && clazz.getFriendlyName().length() > 0)
classElement.setAttribute("name", clazz.getFriendlyName());
if (appendDerivation)
classElement.setAttribute("includeDerived", Boolean.toString(clazz.isIncludeDerived()));
}
/**
* Sends the given string to the log with <code>Level.FINE</code>, if that log level is enabled.
*
* @param s The string to send to the log.
*/
public void debugXML(String s) {
if (log.isLoggable(Level.FINE)) {
log.fine("-------------------------------------------------------------------------------------");
log.fine("\n" + s);
log.fine("-------------------------------------------------------------------------------------");
}
}
/* ############################################################################################# */
public abstract class DIDLObjectHandler<I extends DIDLObject> extends Handler<I> {
protected DIDLObjectHandler(I instance, Handler parent) {
super(instance, parent);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
super.endElement(uri, localName, qName);
if (DIDLObject.Property.DC.NAMESPACE.URI.equals(uri)) {
if ("title".equals(localName)) {
getInstance().setTitle(getCharacters());
} else if ("creator".equals(localName)) {
getInstance().setCreator(getCharacters());
} else if ("description".equals(localName)) {
getInstance().addProperty(new DIDLObject.Property.DC.DESCRIPTION(getCharacters()));
} else if ("publisher".equals(localName)) {
getInstance().addProperty(new DIDLObject.Property.DC.PUBLISHER(new Person(getCharacters())));
} else if ("contributor".equals(localName)) {
getInstance().addProperty(new DIDLObject.Property.DC.CONTRIBUTOR(new Person(getCharacters())));
} else if ("date".equals(localName)) {
getInstance().addProperty(new DIDLObject.Property.DC.DATE(getCharacters()));
} else if ("language".equals(localName)) {
getInstance().addProperty(new DIDLObject.Property.DC.LANGUAGE(getCharacters()));
} else if ("rights".equals(localName)) {
getInstance().addProperty(new DIDLObject.Property.DC.RIGHTS(getCharacters()));
} else if ("relation".equals(localName)) {
getInstance().addProperty(new DIDLObject.Property.DC.RELATION(URI.create(getCharacters())));
}
} else if (DIDLObject.Property.UPNP.NAMESPACE.URI.equals(uri)) {
if ("writeStatus".equals(localName)) {
try {
getInstance().setWriteStatus(
WriteStatus.valueOf(getCharacters())
);
} catch (Exception ex) {
log.info("Ignoring invalid writeStatus value: " + getCharacters());
}
} else if ("class".equals(localName)) {
getInstance().setClazz(
new DIDLObject.Class(
getCharacters(),
getAttributes().getValue("name")
)
);
} else if ("artist".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.ARTIST(
new PersonWithRole(getCharacters(), getAttributes().getValue("role"))
)
);
} else if ("actor".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.ACTOR(
new PersonWithRole(getCharacters(), getAttributes().getValue("role"))
)
);
} else if ("author".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.AUTHOR(
new PersonWithRole(getCharacters(), getAttributes().getValue("role"))
)
);
} else if ("producer".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.PRODUCER(new Person(getCharacters()))
);
} else if ("director".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.DIRECTOR(new Person(getCharacters()))
);
} else if ("longDescription".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.LONG_DESCRIPTION(getCharacters())
);
} else if ("storageUsed".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.STORAGE_USED(Long.valueOf(getCharacters()))
);
} else if ("storageTotal".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.STORAGE_TOTAL(Long.valueOf(getCharacters()))
);
} else if ("storageFree".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.STORAGE_FREE(Long.valueOf(getCharacters()))
);
} else if ("storageMaxPartition".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.STORAGE_MAX_PARTITION(Long.valueOf(getCharacters()))
);
} else if ("storageMedium".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.STORAGE_MEDIUM(StorageMedium.valueOrVendorSpecificOf(getCharacters()))
);
} else if ("genre".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.GENRE(getCharacters())
);
} else if ("album".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.ALBUM(getCharacters())
);
} else if ("playlist".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.PLAYLIST(getCharacters())
);
} else if ("region".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.REGION(getCharacters())
);
} else if ("rating".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.RATING(getCharacters())
);
} else if ("toc".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.TOC(getCharacters())
);
} else if ("albumArtURI".equals(localName)) {
DIDLObject.Property albumArtURI = new DIDLObject.Property.UPNP.ALBUM_ART_URI(URI.create(getCharacters()));
Attributes albumArtURIAttributes = getAttributes();
for (int i = 0; i < albumArtURIAttributes.getLength(); i++) {
if ("profileID".equals(albumArtURIAttributes.getLocalName(i))) {
albumArtURI.addAttribute(
new DIDLObject.Property.DLNA.PROFILE_ID(
new DIDLAttribute(
DIDLObject.Property.DLNA.NAMESPACE.URI,
"dlna",
albumArtURIAttributes.getValue(i))
));
}
}
getInstance().addProperty(albumArtURI);
} else if ("artistDiscographyURI".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.ARTIST_DISCO_URI(URI.create(getCharacters()))
);
} else if ("lyricsURI".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.LYRICS_URI(URI.create(getCharacters()))
);
} else if ("icon".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.ICON(URI.create(getCharacters()))
);
} else if ("radioCallSign".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.RADIO_CALL_SIGN(getCharacters())
);
} else if ("radioStationID".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.RADIO_STATION_ID(getCharacters())
);
} else if ("radioBand".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.RADIO_BAND(getCharacters())
);
} else if ("channelNr".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.CHANNEL_NR(Integer.valueOf(getCharacters()))
);
} else if ("channelName".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.CHANNEL_NAME(getCharacters())
);
} else if ("scheduledStartTime".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.SCHEDULED_START_TIME(getCharacters())
);
} else if ("scheduledEndTime".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.SCHEDULED_END_TIME(getCharacters())
);
} else if ("DVDRegionCode".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.DVD_REGION_CODE(Integer.valueOf(getCharacters()))
);
} else if ("originalTrackNumber".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.ORIGINAL_TRACK_NUMBER(Integer.valueOf(getCharacters()))
);
} else if ("userAnnotation".equals(localName)) {
getInstance().addProperty(
new DIDLObject.Property.UPNP.USER_ANNOTATION(getCharacters())
);
}
}
}
}
public class RootHandler extends Handler<DIDLContent> {
RootHandler(DIDLContent instance, SAXParser parser) {
super(instance, parser);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
super.startElement(uri, localName, qName, attributes);
if (!DIDLContent.NAMESPACE_URI.equals(uri)) return;
if (localName.equals("container")) {
Container container = createContainer(attributes);
getInstance().addContainer(container);
createContainerHandler(container, this);
} else if (localName.equals("item")) {
Item item = createItem(attributes);
getInstance().addItem(item);
createItemHandler(item, this);
} else if (localName.equals("desc")) {
DescMeta desc = createDescMeta(attributes);
getInstance().addDescMetadata(desc);
createDescMetaHandler(desc, this);
}
}
@Override
protected boolean isLastElement(String uri, String localName, String qName) {
if (DIDLContent.NAMESPACE_URI.equals(uri) && "DIDL-Lite".equals(localName)) {
// Now transform all the generically typed Container and Item instances into
// more specific Album, MusicTrack, etc. instances
getInstance().replaceGenericContainerAndItems();
return true;
}
return false;
}
}
public class ContainerHandler extends DIDLObjectHandler<Container> {
public ContainerHandler(Container instance, Handler parent) {
super(instance, parent);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
super.startElement(uri, localName, qName, attributes);
if (!DIDLContent.NAMESPACE_URI.equals(uri)) return;
if (localName.equals("item")) {
Item item = createItem(attributes);
getInstance().addItem(item);
createItemHandler(item, this);
} else if (localName.equals("desc")) {
DescMeta desc = createDescMeta(attributes);
getInstance().addDescMetadata(desc);
createDescMetaHandler(desc, this);
} else if (localName.equals("res")) {
Res res = createResource(attributes);
if (res != null) {
getInstance().addResource(res);
createResHandler(res, this);
}
}
// We do NOT support recursive container embedded in container! The schema allows it
// but the spec doesn't:
//
// Section 2.8.3: Incremental navigation i.e. the full hierarchy is never returned
// in one call since this is likely to flood the resources available to the control
// point (memory, network bandwidth, etc.).
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
super.endElement(uri, localName, qName);
if (DIDLObject.Property.UPNP.NAMESPACE.URI.equals(uri)) {
if ("searchClass".equals(localName)) {
getInstance().getSearchClasses().add(
new DIDLObject.Class(
getCharacters(),
getAttributes().getValue("name"),
"true".equals(getAttributes().getValue("includeDerived"))
)
);
} else if ("createClass".equals(localName)) {
getInstance().getCreateClasses().add(
new DIDLObject.Class(
getCharacters(),
getAttributes().getValue("name"),
"true".equals(getAttributes().getValue("includeDerived"))
)
);
}
}
}
@Override
protected boolean isLastElement(String uri, String localName, String qName) {
if (DIDLContent.NAMESPACE_URI.equals(uri) && "container".equals(localName)) {
if (getInstance().getTitle() == null) {
log.warning("In DIDL content, missing 'dc:title' element for container: " + getInstance().getId());
}
if (getInstance().getClazz() == null) {
log.warning("In DIDL content, missing 'upnp:class' element for container: " + getInstance().getId());
}
return true;
}
return false;
}
}
public class ItemHandler extends DIDLObjectHandler<Item> {
public ItemHandler(Item instance, Handler parent) {
super(instance, parent);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
super.startElement(uri, localName, qName, attributes);
if (!DIDLContent.NAMESPACE_URI.equals(uri)) return;
if (localName.equals("res")) {
Res res = createResource(attributes);
if (res != null) {
getInstance().addResource(res);
createResHandler(res, this);
}
} else if (localName.equals("desc")) {
DescMeta desc = createDescMeta(attributes);
getInstance().addDescMetadata(desc);
createDescMetaHandler(desc, this);
}
}
@Override
protected boolean isLastElement(String uri, String localName, String qName) {
if (DIDLContent.NAMESPACE_URI.equals(uri) && "item".equals(localName)) {
if (getInstance().getTitle() == null) {
log.warning("In DIDL content, missing 'dc:title' element for item: " + getInstance().getId());
}
if (getInstance().getClazz() == null) {
log.warning("In DIDL content, missing 'upnp:class' element for item: " + getInstance().getId());
}
return true;
}
return false;
}
}
protected class ResHandler extends Handler<Res> {
public ResHandler(Res instance, Handler parent) {
super(instance, parent);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
super.endElement(uri, localName, qName);
getInstance().setValue(getCharacters());
}
@Override
protected boolean isLastElement(String uri, String localName, String qName) {
return DIDLContent.NAMESPACE_URI.equals(uri) && "res".equals(localName);
}
}
/**
* Extracts an <code>org.w3c.Document</code> from the nested elements in the {@code <desc>} element.
* <p>
* The root element of this document is a wrapper in the namespace
* {@link org.teleal.cling.support.model.DIDLContent#DESC_WRAPPER_NAMESPACE_URI}.
* </p>
*/
public class DescMetaHandler extends Handler<DescMeta> {
protected Element current;
public DescMetaHandler(DescMeta instance, Handler parent) {
super(instance, parent);
instance.setMetadata(instance.createMetadataDocument());
current = getInstance().getMetadata().getDocumentElement();
}
@Override
public DescMeta<Document> getInstance() {
return super.getInstance();
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
super.startElement(uri, localName, qName, attributes);
Element newEl = getInstance().getMetadata().createElementNS(uri, qName);
for (int i = 0; i < attributes.getLength(); i++) {
newEl.setAttributeNS(
attributes.getURI(i),
attributes.getQName(i),
attributes.getValue(i)
);
}
current.appendChild(newEl);
current = newEl;
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
super.endElement(uri, localName, qName);
if (isLastElement(uri, localName, qName)) return;
// Ignore whitespace
if (getCharacters().length() > 0 && !getCharacters().matches("[\\t\\n\\x0B\\f\\r\\s]+"))
current.appendChild(getInstance().getMetadata().createTextNode(getCharacters()));
current = (Element) current.getParentNode();
// Reset this so we can continue parsing child nodes with this handler
characters = new StringBuilder();
attributes = null;
}
@Override
protected boolean isLastElement(String uri, String localName, String qName) {
return DIDLContent.NAMESPACE_URI.equals(uri) && "desc".equals(localName);
}
}
}
| zzh84615-mycode | src/org/teleal/cling/support/contentdirectory/DIDLParser.java | Java | asf20 | 45,006 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.contentdirectory;
import org.teleal.cling.model.action.ActionException;
import org.teleal.cling.model.types.ErrorCode;
/**
* @author Alessio Gaeta
*/
public class ContentDirectoryException extends ActionException {
public ContentDirectoryException(int errorCode, String message) {
super(errorCode, message);
}
public ContentDirectoryException(int errorCode, String message,
Throwable cause) {
super(errorCode, message, cause);
}
public ContentDirectoryException(ErrorCode errorCode, String message) {
super(errorCode, message);
}
public ContentDirectoryException(ErrorCode errorCode) {
super(errorCode);
}
public ContentDirectoryException(ContentDirectoryErrorCode errorCode, String message) {
super(errorCode.getCode(), errorCode.getDescription() + ". " + message + ".");
}
public ContentDirectoryException(ContentDirectoryErrorCode errorCode) {
super(errorCode.getCode(), errorCode.getDescription());
}
}
| zzh84615-mycode | src/org/teleal/cling/support/contentdirectory/ContentDirectoryException.java | Java | asf20 | 1,809 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.contentdirectory;
/**
* @author Alessio Gaeta
*/
public enum ContentDirectoryErrorCode {
NO_SUCH_OBJECT(701, "The specified ObjectID is invalid"),
UNSUPPORTED_SORT_CRITERIA(709, "Unsupported or invalid sort criteria"),
CANNOT_PROCESS(720, "Cannot process the request");
private int code;
private String description;
ContentDirectoryErrorCode(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static ContentDirectoryErrorCode getByCode(int code) {
for (ContentDirectoryErrorCode errorCode : values()) {
if (errorCode.getCode() == code)
return errorCode;
}
return null;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/contentdirectory/ContentDirectoryErrorCode.java | Java | asf20 | 1,514 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.contentdirectory.ui;
import org.teleal.cling.model.action.ActionException;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.message.UpnpResponse;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.support.model.BrowseFlag;
import org.teleal.cling.support.model.DIDLContent;
import org.teleal.cling.support.model.SortCriterion;
import org.teleal.cling.support.contentdirectory.callback.Browse;
import org.teleal.cling.model.types.ErrorCode;
import org.teleal.cling.support.model.container.Container;
import org.teleal.cling.support.model.item.Item;
import com.wireme.activity.ContentItem;
import android.R.anim;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
/**
* Updates a tree model after querying a backend <em>ContentDirectory</em>
* service.
*
* @author Christian Bauer
*/
public class ContentBrowseActionCallback extends Browse {
private static Logger log = Logger
.getLogger(ContentBrowseActionCallback.class.getName());
private Service service;
private Container container;
private ArrayAdapter<ContentItem> listAdapter;
private Activity activity;
public ContentBrowseActionCallback(Activity activity, Service service,
Container container, ArrayAdapter<ContentItem> listadapter) {
super(service, container.getId(), BrowseFlag.DIRECT_CHILDREN, "*", 0,
null, new SortCriterion(true, "dc:title"));
this.activity = activity;
this.service = service;
this.container = container;
this.listAdapter = listadapter;
}
public void received(final ActionInvocation actionInvocation,
final DIDLContent didl) {
log.fine("Received browse action DIDL descriptor, creating tree nodes");
activity.runOnUiThread(new Runnable() {
public void run() {
try {
listAdapter.clear();
// Containers first
for (Container childContainer : didl.getContainers()) {
log.fine("add child container " + childContainer.getTitle());
listAdapter.add(new ContentItem(childContainer, service));
}
// Now items
for (Item childItem : didl.getItems()) {
log.fine("add child item" + childItem.getTitle());
listAdapter.add(new ContentItem(childItem, service));
}
} catch (Exception ex) {
log.fine("Creating DIDL tree nodes failed: " + ex);
actionInvocation.setFailure(new ActionException(
ErrorCode.ACTION_FAILED,
"Can't create list childs: " + ex, ex));
failure(actionInvocation, null);
}
}
});
}
public void updateStatus(final Status status) {
}
@Override
public void failure(ActionInvocation invocation, UpnpResponse operation,
final String defaultMsg) {
}
}
| zzh84615-mycode | src/org/teleal/cling/support/contentdirectory/ui/ContentBrowseActionCallback.java | Java | asf20 | 3,539 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.contentdirectory.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionException;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.ErrorCode;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.contentdirectory.DIDLParser;
import org.teleal.cling.support.model.BrowseFlag;
import org.teleal.cling.support.model.BrowseResult;
import org.teleal.cling.support.model.DIDLContent;
import org.teleal.cling.support.model.SortCriterion;
import java.util.logging.Logger;
/**
* Invokes a "Browse" action, parses the result.
*
* @author Christian Bauer
*/
public abstract class Browse extends ActionCallback {
public static final String CAPS_WILDCARD = "*";
public enum Status {
NO_CONTENT("No Content"),
LOADING("Loading..."),
OK("OK");
private String defaultMessage;
Status(String defaultMessage) {
this.defaultMessage = defaultMessage;
}
public String getDefaultMessage() {
return defaultMessage;
}
}
private static Logger log = Logger.getLogger(Browse.class.getName());
/**
* Browse with first result 0 and {@link #getDefaultMaxResults()}, filters with {@link #CAPS_WILDCARD}.
*/
public Browse(Service service, String containerId, BrowseFlag flag) {
this(service, containerId, flag, CAPS_WILDCARD, 0, null);
}
/**
* @param maxResults Can be <code>null</code>, then {@link #getDefaultMaxResults()} is used.
*/
public Browse(Service service, String objectID, BrowseFlag flag,
String filter, long firstResult, Long maxResults, SortCriterion... orderBy) {
super(new ActionInvocation(service.getAction("Browse")));
log.fine("Creating browse action for object ID: " + objectID);
getActionInvocation().setInput("ObjectID", objectID);
getActionInvocation().setInput("BrowseFlag", flag.toString());
getActionInvocation().setInput("Filter", filter);
getActionInvocation().setInput("StartingIndex", new UnsignedIntegerFourBytes(firstResult));
getActionInvocation().setInput("RequestedCount",
new UnsignedIntegerFourBytes(maxResults == null ? getDefaultMaxResults() : maxResults)
);
getActionInvocation().setInput("SortCriteria", SortCriterion.toString(orderBy));
}
@Override
public void run() {
updateStatus(Status.LOADING);
super.run();
}
public void success(ActionInvocation invocation) {
log.fine("Successful browse action, reading output argument values");
BrowseResult result = new BrowseResult(
invocation.getOutput("Result").getValue().toString(),
(UnsignedIntegerFourBytes) invocation.getOutput("NumberReturned").getValue(),
(UnsignedIntegerFourBytes) invocation.getOutput("TotalMatches").getValue(),
(UnsignedIntegerFourBytes) invocation.getOutput("UpdateID").getValue()
);
boolean proceed = receivedRaw(invocation, result);
if (proceed && result.getCountLong() > 0 && result.getResult().length() > 0) {
try {
DIDLParser didlParser = new DIDLParser();
DIDLContent didl = didlParser.parse(result.getResult());
received(invocation, didl);
updateStatus(Status.OK);
} catch (Exception ex) {
invocation.setFailure(
new ActionException(ErrorCode.ACTION_FAILED, "Can't parse DIDL XML response: " + ex, ex)
);
failure(invocation, null);
}
} else {
received(invocation, new DIDLContent());
updateStatus(Status.NO_CONTENT);
}
}
/**
* Some media servers will crash if there is no limit on the maximum number of results.
*
* @return The default limit, 999.
*/
public long getDefaultMaxResults() {
return 999;
}
public boolean receivedRaw(ActionInvocation actionInvocation, BrowseResult browseResult) {
/*
if (log.isLoggable(Level.FINER)) {
log.finer("-------------------------------------------------------------------------------------");
log.finer("\n" + XML.pretty(browseResult.getDidl()));
log.finer("-------------------------------------------------------------------------------------");
}
*/
return true;
}
public abstract void received(ActionInvocation actionInvocation, DIDLContent didl);
public abstract void updateStatus(Status status);
}
| zzh84615-mycode | src/org/teleal/cling/support/contentdirectory/callback/Browse.java | Java | asf20 | 5,558 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.shared;
import org.teleal.common.swingfwk.logging.LogCategory;
import java.util.ArrayList;
import java.util.logging.Level;
/**
* @author Christian Bauer
*/
public class LogCategories extends ArrayList<LogCategory> {
public LogCategories() {
super(10);
add(new LogCategory("Network", new LogCategory.Group[]{
new LogCategory.Group(
"UDP communication",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.DatagramIO.class.getName(), Level.FINE),
new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.MulticastReceiver.class.getName(), Level.FINE),
}
),
new LogCategory.Group(
"UDP datagram processing and content",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.DatagramProcessor.class.getName(), Level.FINER)
}
),
new LogCategory.Group(
"TCP communication",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.UpnpStream.class.getName(), Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.StreamServer.class.getName(), Level.FINE),
new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.StreamClient.class.getName(), Level.FINE),
}
),
new LogCategory.Group(
"SOAP action message processing and content",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.SOAPActionProcessor.class.getName(), Level.FINER)
}
),
new LogCategory.Group(
"GENA event message processing and content",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel(org.teleal.cling.transport.spi.GENAEventProcessor.class.getName(), Level.FINER)
}
),
new LogCategory.Group(
"HTTP header processing",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel(org.teleal.cling.model.message.UpnpHeaders.class.getName(), Level.FINER)
}
),
}));
add(new LogCategory("UPnP Protocol", new LogCategory.Group[]{
new LogCategory.Group(
"Discovery (Notification & Search)",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel(org.teleal.cling.protocol.ProtocolFactory.class.getName(), Level.FINER),
new LogCategory.LoggerLevel("org.teleal.cling.protocol.async", Level.FINER)
}
),
new LogCategory.Group(
"Description",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel(org.teleal.cling.protocol.ProtocolFactory.class.getName(), Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.RetrieveRemoteDescriptors.class.getName(), Level.FINE),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.ReceivingRetrieval.class.getName(), Level.FINE),
new LogCategory.LoggerLevel(org.teleal.cling.binding.xml.DeviceDescriptorBinder.class.getName(), Level.FINE),
new LogCategory.LoggerLevel(org.teleal.cling.binding.xml.ServiceDescriptorBinder.class.getName(), Level.FINE),
}
),
new LogCategory.Group(
"Control",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel(org.teleal.cling.protocol.ProtocolFactory.class.getName(), Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.ReceivingAction.class.getName(), Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.SendingAction.class.getName(), Level.FINER),
}
),
new LogCategory.Group(
"GENA ",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel("org.teleal.cling.model.gena", Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.ProtocolFactory.class.getName(), Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.ReceivingEvent.class.getName(), Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.ReceivingSubscribe.class.getName(), Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.ReceivingUnsubscribe.class.getName(), Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.SendingEvent.class.getName(), Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.SendingSubscribe.class.getName(), Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.SendingUnsubscribe.class.getName(), Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.protocol.sync.SendingRenewal.class.getName(), Level.FINER),
}
),
}));
add(new LogCategory("Core", new LogCategory.Group[]{
new LogCategory.Group(
"Router",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel(org.teleal.cling.transport.Router.class.getName(), Level.FINER)
}
),
new LogCategory.Group(
"Registry",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel(org.teleal.cling.registry.Registry.class.getName(), Level.FINER),
}
),
new LogCategory.Group(
"Local service binding & invocation",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel("org.teleal.cling.binding.annotations", Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.model.meta.LocalService.class.getName(), Level.FINER),
new LogCategory.LoggerLevel("org.teleal.cling.model.action", Level.FINER),
new LogCategory.LoggerLevel("org.teleal.cling.model.state", Level.FINER),
new LogCategory.LoggerLevel(org.teleal.cling.model.DefaultServiceManager.class.getName(), Level.FINER)
}
),
new LogCategory.Group(
"Control Point interaction",
new LogCategory.LoggerLevel[]{
new LogCategory.LoggerLevel("org.teleal.cling.controlpoint", Level.FINER),
}
),
}));
}
}
| zzh84615-mycode | src/org/teleal/cling/support/shared/LogCategories.java | Java | asf20 | 8,666 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.shared;
import org.teleal.common.swingfwk.DefaultEvent;
public class TextExpandEvent extends DefaultEvent<String> {
public TextExpandEvent(String s) {
super(s);
}
}
| zzh84615-mycode | src/org/teleal/cling/support/shared/TextExpandEvent.java | Java | asf20 | 943 |
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.teleal.cling.support.shared;
import java.io.Serializable;
import java.util.*;
/**
* A base class for {@code Map} implementations.
*
* <p>Subclasses that permit new mappings to be added must override {@link
* #put}.
*
* <p>The default implementations of many methods are inefficient for large
* maps. For example in the default implementation, each call to {@link #get}
* performs a linear iteration of the entry set. Subclasses should override such
* methods to improve their performance.
*
* @since 1.2
*/
public abstract class AbstractMap<K, V> implements Map<K, V> {
// Lazily initialized key set.
Set<K> keySet;
Collection<V> valuesCollection;
/**
* An immutable key-value mapping. Despite the name, this class is non-final
* and its subclasses may be mutable.
*
* @since 1.6
*/
public static class SimpleImmutableEntry<K, V>
implements Map.Entry<K, V>, Serializable {
private static final long serialVersionUID = 7138329143949025153L;
private final K key;
private final V value;
public SimpleImmutableEntry(K theKey, V theValue) {
key = theKey;
value = theValue;
}
/**
* Constructs an instance with the key and value of {@code copyFrom}.
*/
public SimpleImmutableEntry(Map.Entry<? extends K, ? extends V> copyFrom) {
key = copyFrom.getKey();
value = copyFrom.getValue();
}
public K getKey() {
return key;
}
public V getValue() {
return value;
}
/**
* This base implementation throws {@code UnsupportedOperationException}
* always.
*/
public V setValue(V object) {
throw new UnsupportedOperationException();
}
@Override public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Map.Entry) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) object;
return (key == null ? entry.getKey() == null : key.equals(entry
.getKey()))
&& (value == null ? entry.getValue() == null : value
.equals(entry.getValue()));
}
return false;
}
@Override public int hashCode() {
return (key == null ? 0 : key.hashCode())
^ (value == null ? 0 : value.hashCode());
}
@Override public String toString() {
return key + "=" + value;
}
}
/**
* A key-value mapping with mutable values.
*
* @since 1.6
*/
public static class SimpleEntry<K, V>
implements Map.Entry<K, V>, Serializable {
private static final long serialVersionUID = -8499721149061103585L;
private final K key;
private V value;
public SimpleEntry(K theKey, V theValue) {
key = theKey;
value = theValue;
}
/**
* Constructs an instance with the key and value of {@code copyFrom}.
*/
public SimpleEntry(Map.Entry<? extends K, ? extends V> copyFrom) {
key = copyFrom.getKey();
value = copyFrom.getValue();
}
public K getKey() {
return key;
}
public V getValue() {
return value;
}
public V setValue(V object) {
V result = value;
value = object;
return result;
}
@Override public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Map.Entry) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) object;
return (key == null ? entry.getKey() == null : key.equals(entry
.getKey()))
&& (value == null ? entry.getValue() == null : value
.equals(entry.getValue()));
}
return false;
}
@Override public int hashCode() {
return (key == null ? 0 : key.hashCode())
^ (value == null ? 0 : value.hashCode());
}
@Override public String toString() {
return key + "=" + value;
}
}
protected AbstractMap() {
super();
}
/**
* {@inheritDoc}
*
* <p>This implementation calls {@code entrySet().clear()}.
*/
public void clear() {
entrySet().clear();
}
/**
* {@inheritDoc}
*
* <p>This implementation iterates its key set, looking for a key that
* {@code key} equals.
*/
public boolean containsKey(Object key) {
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
if (key != null) {
while (it.hasNext()) {
if (key.equals(it.next().getKey())) {
return true;
}
}
} else {
while (it.hasNext()) {
if (it.next().getKey() == null) {
return true;
}
}
}
return false;
}
/**
* {@inheritDoc}
*
* <p>This implementation iterates its entry set, looking for an entry with
* a value that {@code value} equals.
*/
public boolean containsValue(Object value) {
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
if (value != null) {
while (it.hasNext()) {
if (value.equals(it.next().getValue())) {
return true;
}
}
} else {
while (it.hasNext()) {
if (it.next().getValue() == null) {
return true;
}
}
}
return false;
}
public abstract Set<Map.Entry<K, V>> entrySet();
/**
* {@inheritDoc}
*
* <p>This implementation first checks the structure of {@code object}. If
* it is not a map or of a different size, this returns false. Otherwise it
* iterates its own entry set, looking up each entry's key in {@code
* object}. If any value does not equal the other map's value for the same
* key, this returns false. Otherwise it returns true.
*/
@Override public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Map) {
Map<?, ?> map = (Map<?, ?>) object;
if (size() != map.size()) {
return false;
}
try {
for (Entry<K, V> entry : entrySet()) {
K key = entry.getKey();
V mine = entry.getValue();
Object theirs = map.get(key);
if (mine == null) {
if (theirs != null || !map.containsKey(key)) {
return false;
}
} else if (!mine.equals(theirs)) {
return false;
}
}
} catch (NullPointerException ignored) {
return false;
} catch (ClassCastException ignored) {
return false;
}
return true;
}
return false;
}
/**
* {@inheritDoc}
*
* <p>This implementation iterates its entry set, looking for an entry with
* a key that {@code key} equals.
*/
public V get(Object key) {
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
if (key != null) {
while (it.hasNext()) {
Map.Entry<K, V> entry = it.next();
if (key.equals(entry.getKey())) {
return entry.getValue();
}
}
} else {
while (it.hasNext()) {
Map.Entry<K, V> entry = it.next();
if (entry.getKey() == null) {
return entry.getValue();
}
}
}
return null;
}
/**
* {@inheritDoc}
*
* <p>This implementation iterates its entry set, summing the hashcodes of
* its entries.
*/
@Override public int hashCode() {
int result = 0;
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
while (it.hasNext()) {
result += it.next().hashCode();
}
return result;
}
/**
* {@inheritDoc}
*
* <p>This implementation compares {@code size()} to 0.
*/
public boolean isEmpty() {
return size() == 0;
}
/**
* {@inheritDoc}
*
* <p>This implementation returns a view that calls through this to map. Its
* iterator transforms this map's entry set iterator to return keys.
*/
public Set<K> keySet() {
if (keySet == null) {
keySet = new AbstractSet<K>() {
@Override public boolean contains(Object object) {
return containsKey(object);
}
@Override public int size() {
return AbstractMap.this.size();
}
@Override public Iterator<K> iterator() {
return new Iterator<K>() {
Iterator<Map.Entry<K, V>> setIterator = entrySet().iterator();
public boolean hasNext() {
return setIterator.hasNext();
}
public K next() {
return setIterator.next().getKey();
}
public void remove() {
setIterator.remove();
}
};
}
};
}
return keySet;
}
/**
* {@inheritDoc}
*
* <p>This base implementation throws {@code UnsupportedOperationException}.
*/
public V put(K key, V value) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
* <p>This implementation iterates through {@code map}'s entry set, calling
* {@code put()} for each.
*/
public void putAll(Map<? extends K, ? extends V> map) {
for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
}
/**
* {@inheritDoc}
*
* <p>This implementation iterates its entry set, removing the entry with
* a key that {@code key} equals.
*/
public V remove(Object key) {
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
if (key != null) {
while (it.hasNext()) {
Map.Entry<K, V> entry = it.next();
if (key.equals(entry.getKey())) {
it.remove();
return entry.getValue();
}
}
} else {
while (it.hasNext()) {
Map.Entry<K, V> entry = it.next();
if (entry.getKey() == null) {
it.remove();
return entry.getValue();
}
}
}
return null;
}
/**
* {@inheritDoc}
*
* <p>This implementation returns its entry set's size.
*/
public int size() {
return entrySet().size();
}
/**
* {@inheritDoc}
*
* <p>This implementation composes a string by iterating its entry set. If
* this map contains itself as a key or a value, the string "(this Map)"
* will appear in its place.
*/
@Override public String toString() {
if (isEmpty()) {
return "{}";
}
StringBuilder buffer = new StringBuilder(size() * 28);
buffer.append('{');
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
while (it.hasNext()) {
Map.Entry<K, V> entry = it.next();
Object key = entry.getKey();
if (key != this) {
buffer.append(key);
} else {
buffer.append("(this Map)");
}
buffer.append('=');
Object value = entry.getValue();
if (value != this) {
buffer.append(value);
} else {
buffer.append("(this Map)");
}
if (it.hasNext()) {
buffer.append(", ");
}
}
buffer.append('}');
return buffer.toString();
}
/**
* {@inheritDoc}
*
* <p>This implementation returns a view that calls through this to map. Its
* iterator transforms this map's entry set iterator to return values.
*/
public Collection<V> values() {
if (valuesCollection == null) {
valuesCollection = new AbstractCollection<V>() {
@Override public int size() {
return AbstractMap.this.size();
}
@Override public boolean contains(Object object) {
return containsValue(object);
}
@Override public Iterator<V> iterator() {
return new Iterator<V>() {
Iterator<Map.Entry<K, V>> setIterator = entrySet().iterator();
public boolean hasNext() {
return setIterator.hasNext();
}
public V next() {
return setIterator.next().getValue();
}
public void remove() {
setIterator.remove();
}
};
}
};
}
return valuesCollection;
}
@SuppressWarnings("unchecked")
@Override protected Object clone() throws CloneNotSupportedException {
AbstractMap<K, V> result = (AbstractMap<K, V>) super.clone();
result.keySet = null;
result.valuesCollection = null;
return result;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/shared/AbstractMap.java | Java | asf20 | 15,158 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.shared;
/**
* @author Christian Bauer
*/
public class AWTExceptionHandler {
public void handle(Throwable ex) {
System.err.println("============= The application encountered an unrecoverable error, exiting... =============");
ex.printStackTrace(System.err);
System.err.println("==========================================================================================");
System.exit(1);
}
}
| zzh84615-mycode | src/org/teleal/cling/support/shared/AWTExceptionHandler.java | Java | asf20 | 1,194 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport;
import org.teleal.cling.binding.annotations.UpnpAction;
import org.teleal.cling.binding.annotations.UpnpInputArgument;
import org.teleal.cling.binding.annotations.UpnpOutputArgument;
import org.teleal.cling.binding.annotations.UpnpService;
import org.teleal.cling.binding.annotations.UpnpServiceId;
import org.teleal.cling.binding.annotations.UpnpServiceType;
import org.teleal.cling.binding.annotations.UpnpStateVariable;
import org.teleal.cling.binding.annotations.UpnpStateVariables;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.model.TransportState;
import org.teleal.cling.support.model.DeviceCapabilities;
import org.teleal.cling.support.model.MediaInfo;
import org.teleal.cling.support.model.PlayMode;
import org.teleal.cling.support.model.PositionInfo;
import org.teleal.cling.support.model.RecordMediumWriteStatus;
import org.teleal.cling.support.model.RecordQualityMode;
import org.teleal.cling.support.model.SeekMode;
import org.teleal.cling.support.model.TransportInfo;
import org.teleal.cling.support.model.TransportSettings;
import org.teleal.cling.support.model.TransportStatus;
import org.teleal.cling.support.avtransport.lastchange.AVTransportLastChangeParser;
import org.teleal.cling.support.model.StorageMedium;
import org.teleal.cling.support.lastchange.LastChange;
import java.beans.PropertyChangeSupport;
/**
* Skeleton of service with "LastChange" eventing support.
*
* @author Christian Bauer
*/
@UpnpService(
serviceId = @UpnpServiceId("AVTransport"),
serviceType = @UpnpServiceType(value = "AVTransport", version = 1),
stringConvertibleTypes = LastChange.class
)
@UpnpStateVariables({
@UpnpStateVariable(
name = "TransportState",
sendEvents = false,
allowedValuesEnum = TransportState.class),
@UpnpStateVariable(
name = "TransportStatus",
sendEvents = false,
allowedValuesEnum = TransportStatus.class),
@UpnpStateVariable(
name = "PlaybackStorageMedium",
sendEvents = false,
defaultValue = "NONE",
allowedValuesEnum = StorageMedium.class),
@UpnpStateVariable(
name = "RecordStorageMedium",
sendEvents = false,
defaultValue = "NOT_IMPLEMENTED",
allowedValuesEnum = StorageMedium.class),
@UpnpStateVariable(
name = "PossiblePlaybackStorageMedia",
sendEvents = false,
datatype = "string",
defaultValue = "NETWORK"),
@UpnpStateVariable(
name = "PossibleRecordStorageMedia",
sendEvents = false,
datatype = "string",
defaultValue = "NOT_IMPLEMENTED"),
@UpnpStateVariable( // TODO
name = "CurrentPlayMode",
sendEvents = false,
defaultValue = "NORMAL",
allowedValuesEnum = PlayMode.class),
@UpnpStateVariable( // TODO
name = "TransportPlaySpeed",
sendEvents = false,
datatype = "string",
defaultValue = "1"), // 1, 1/2, 2, -1, 1/10, etc.
@UpnpStateVariable(
name = "RecordMediumWriteStatus",
sendEvents = false,
defaultValue = "NOT_IMPLEMENTED",
allowedValuesEnum = RecordMediumWriteStatus.class),
@UpnpStateVariable(
name = "CurrentRecordQualityMode",
sendEvents = false,
defaultValue = "NOT_IMPLEMENTED",
allowedValuesEnum = RecordQualityMode.class),
@UpnpStateVariable(
name = "PossibleRecordQualityModes",
sendEvents = false,
datatype = "string",
defaultValue = "NOT_IMPLEMENTED"),
@UpnpStateVariable(
name = "NumberOfTracks",
sendEvents = false,
datatype = "ui4",
defaultValue = "0"),
@UpnpStateVariable(
name = "CurrentTrack",
sendEvents = false,
datatype = "ui4",
defaultValue = "0"),
@UpnpStateVariable(
name = "CurrentTrackDuration",
sendEvents = false,
datatype = "string"), // H+:MM:SS[.F+] or H+:MM:SS[.F0/F1]
@UpnpStateVariable(
name = "CurrentMediaDuration",
sendEvents = false,
datatype = "string",
defaultValue = "00:00:00"),
@UpnpStateVariable(
name = "CurrentTrackMetaData",
sendEvents = false,
datatype = "string",
defaultValue = "NOT_IMPLEMENTED"),
@UpnpStateVariable(
name = "CurrentTrackURI",
sendEvents = false,
datatype = "string"),
@UpnpStateVariable(
name = "AVTransportURI",
sendEvents = false,
datatype = "string"),
@UpnpStateVariable(
name = "AVTransportURIMetaData",
sendEvents = false,
datatype = "string",
defaultValue = "NOT_IMPLEMENTED"),
@UpnpStateVariable(
name = "NextAVTransportURI",
sendEvents = false,
datatype = "string",
defaultValue = "NOT_IMPLEMENTED"),
@UpnpStateVariable(
name = "NextAVTransportURIMetaData",
sendEvents = false,
datatype = "string",
defaultValue = "NOT_IMPLEMENTED"),
@UpnpStateVariable(
name = "RelativeTimePosition",
sendEvents = false,
datatype = "string"), // H+:MM:SS[.F+] or H+:MM:SS[.F0/F1] (in track)
@UpnpStateVariable(
name = "AbsoluteTimePosition",
sendEvents = false,
datatype = "string"), // H+:MM:SS[.F+] or H+:MM:SS[.F0/F1] (in media)
@UpnpStateVariable(
name = "RelativeCounterPosition",
sendEvents = false,
datatype = "i4",
defaultValue = "2147483647"), // Max value means not implemented
@UpnpStateVariable(
name = "AbsoluteCounterPosition",
sendEvents = false,
datatype = "i4",
defaultValue = "2147483647"), // Max value means not implemented
@UpnpStateVariable(
name = "CurrentTransportActions",
sendEvents = false,
datatype = "string"), // Play, Stop, Pause, Seek, Next, Previous and Record
@UpnpStateVariable(
name = "A_ARG_TYPE_SeekMode",
sendEvents = false,
allowedValuesEnum = SeekMode.class), // The 'type' of seek we can perform (or should perform)
@UpnpStateVariable(
name = "A_ARG_TYPE_SeekTarget",
sendEvents = false,
datatype = "string"), // The actual seek (offset or whatever) value
@UpnpStateVariable(
name = "A_ARG_TYPE_InstanceID",
sendEvents = false,
datatype = "ui4")
})
public abstract class AbstractAVTransportService {
@UpnpStateVariable(eventMaximumRateMilliseconds = 200)
final private LastChange lastChange;
final protected PropertyChangeSupport propertyChangeSupport;
protected AbstractAVTransportService() {
this.propertyChangeSupport = new PropertyChangeSupport(this);
this.lastChange = new LastChange(new AVTransportLastChangeParser());
}
protected AbstractAVTransportService(LastChange lastChange) {
this.propertyChangeSupport = new PropertyChangeSupport(this);
this.lastChange = lastChange;
}
protected AbstractAVTransportService(PropertyChangeSupport propertyChangeSupport) {
this.propertyChangeSupport = propertyChangeSupport;
this.lastChange = new LastChange(new AVTransportLastChangeParser());
}
protected AbstractAVTransportService(PropertyChangeSupport propertyChangeSupport, LastChange lastChange) {
this.propertyChangeSupport = propertyChangeSupport;
this.lastChange = lastChange;
}
public LastChange getLastChange() {
return lastChange;
}
public void fireLastChange() {
getLastChange().fire(getPropertyChangeSupport());
}
public PropertyChangeSupport getPropertyChangeSupport() {
return propertyChangeSupport;
}
public static UnsignedIntegerFourBytes getDefaultInstanceID() {
return new UnsignedIntegerFourBytes(0);
}
@UpnpAction
public abstract void setAVTransportURI(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId,
@UpnpInputArgument(name = "CurrentURI", stateVariable = "AVTransportURI") String currentURI,
@UpnpInputArgument(name = "CurrentURIMetaData", stateVariable = "AVTransportURIMetaData") String currentURIMetaData)
throws AVTransportException;
@UpnpAction
public abstract void setNextAVTransportURI(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId,
@UpnpInputArgument(name = "NextURI", stateVariable = "AVTransportURI") String nextURI,
@UpnpInputArgument(name = "NextURIMetaData", stateVariable = "AVTransportURIMetaData") String nextURIMetaData)
throws AVTransportException;
@UpnpAction(out = {
@UpnpOutputArgument(name = "NrTracks", stateVariable = "NumberOfTracks", getterName = "getNumberOfTracks"),
@UpnpOutputArgument(name = "MediaDuration", stateVariable = "CurrentMediaDuration", getterName = "getMediaDuration"),
@UpnpOutputArgument(name = "CurrentURI", stateVariable = "AVTransportURI", getterName = "getCurrentURI"),
@UpnpOutputArgument(name = "CurrentURIMetaData", stateVariable = "AVTransportURIMetaData", getterName = "getCurrentURIMetaData"),
@UpnpOutputArgument(name = "NextURI", stateVariable = "NextAVTransportURI", getterName = "getNextURI"),
@UpnpOutputArgument(name = "NextURIMetaData", stateVariable = "NextAVTransportURIMetaData", getterName = "getNextURIMetaData"),
@UpnpOutputArgument(name = "PlayMedium", stateVariable = "PlaybackStorageMedium", getterName = "getPlayMedium"),
@UpnpOutputArgument(name = "RecordMedium", stateVariable = "RecordStorageMedium", getterName = "getRecordMedium"),
@UpnpOutputArgument(name = "WriteStatus", stateVariable = "RecordMediumWriteStatus", getterName = "getWriteStatus")
})
public abstract MediaInfo getMediaInfo(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId)
throws AVTransportException;
@UpnpAction(out = {
@UpnpOutputArgument(name = "CurrentTransportState", stateVariable = "TransportState", getterName = "getCurrentTransportState"),
@UpnpOutputArgument(name = "CurrentTransportStatus", stateVariable = "TransportStatus", getterName = "getCurrentTransportStatus"),
@UpnpOutputArgument(name = "CurrentSpeed", stateVariable = "TransportPlaySpeed", getterName = "getCurrentSpeed")
})
public abstract TransportInfo getTransportInfo(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId)
throws AVTransportException;
@UpnpAction(out = {
@UpnpOutputArgument(name = "Track", stateVariable = "CurrentTrack", getterName = "getTrack"),
@UpnpOutputArgument(name = "TrackDuration", stateVariable = "CurrentTrackDuration", getterName = "getTrackDuration"),
@UpnpOutputArgument(name = "TrackMetaData", stateVariable = "CurrentTrackMetaData", getterName = "getTrackMetaData"),
@UpnpOutputArgument(name = "TrackURI", stateVariable = "CurrentTrackURI", getterName = "getTrackURI"),
@UpnpOutputArgument(name = "RelTime", stateVariable = "RelativeTimePosition", getterName = "getRelTime"),
@UpnpOutputArgument(name = "AbsTime", stateVariable = "AbsoluteTimePosition", getterName = "getAbsTime"),
@UpnpOutputArgument(name = "RelCount", stateVariable = "RelativeCounterPosition", getterName = "getRelCount"),
@UpnpOutputArgument(name = "AbsCount", stateVariable = "AbsoluteCounterPosition", getterName = "getAbsCount")
})
public abstract PositionInfo getPositionInfo(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId)
throws AVTransportException;
@UpnpAction(out = {
@UpnpOutputArgument(name = "PlayMedia", stateVariable = "PossiblePlaybackStorageMedia", getterName = "getPlayMediaString"),
@UpnpOutputArgument(name = "RecMedia", stateVariable = "PossibleRecordStorageMedia", getterName = "getRecMediaString"),
@UpnpOutputArgument(name = "RecQualityModes", stateVariable = "PossibleRecordQualityModes", getterName = "getRecQualityModesString")
})
public abstract DeviceCapabilities getDeviceCapabilities(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId)
throws AVTransportException;
@UpnpAction(out = {
@UpnpOutputArgument(name = "PlayMode", stateVariable = "CurrentPlayMode", getterName = "getPlayMode"),
@UpnpOutputArgument(name = "RecQualityMode", stateVariable = "CurrentRecordQualityMode", getterName = "getRecQualityMode")
})
public abstract TransportSettings getTransportSettings(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId)
throws AVTransportException;
@UpnpAction
public abstract void stop(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId)
throws AVTransportException;
@UpnpAction
public abstract void play(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId,
@UpnpInputArgument(name = "Speed", stateVariable = "TransportPlaySpeed") String speed)
throws AVTransportException;
@UpnpAction
public abstract void pause(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId)
throws AVTransportException;
@UpnpAction
public abstract void record(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId)
throws AVTransportException;
@UpnpAction
public abstract void seek(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId,
@UpnpInputArgument(name = "Unit", stateVariable = "A_ARG_TYPE_SeekMode") String unit,
@UpnpInputArgument(name = "Target", stateVariable = "A_ARG_TYPE_SeekTarget") String target)
throws AVTransportException;
@UpnpAction
public abstract void next(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId)
throws AVTransportException;
@UpnpAction
public abstract void previous(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId)
throws AVTransportException;
@UpnpAction
public abstract void setPlayMode(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId,
@UpnpInputArgument(name = "NewPlayMode", stateVariable = "CurrentPlayMode") String newPlayMode)
throws AVTransportException;
@UpnpAction
public abstract void setRecordQualityMode(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId,
@UpnpInputArgument(name = "NewRecordQualityMode", stateVariable = "CurrentRecordQualityMode") String newRecordQualityMode)
throws AVTransportException;
@UpnpAction(out = @UpnpOutputArgument(name = "Actions"))
public abstract String getCurrentTransportActions(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId)
throws AVTransportException;
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/AbstractAVTransportService.java | Java | asf20 | 17,151 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport;
/**
*
*/
public enum AVTransportErrorCode {
TRANSITION_NOT_AVAILABLE(701, "The immediate transition from current to desired state not supported"),
NO_CONTENTS(702, "The media does not contain any contents that can be played"),
READ_ERROR(703, "The media cannot be read"),
PLAYBACK_FORMAT_NOT_SUPPORTED(704, "The storage format of the currently loaded media is not supported for playback"),
TRANSPORT_LOCKED(705, "The transport is 'hold locked', e.g. with a keyboard lock"),
WRITE_ERROR(706, "The media cannot be written"),
MEDIA_PROTECTED(707, "The media is write-protected or is of a not writable type"),
RECORD_FORMAT_NOT_SUPPORTED(708, "The storage format of the currently loaded media is not supported for recording"),
MEDIA_FULL(709, "There is no free space left on the loaded media"),
SEEKMODE_NOT_SUPPORTED(710, "The specified seek mode is not supported by the device"),
ILLEGAL_SEEK_TARGET(711, "The specified seek target is not specified in terms of the seek mode, or is not present on the media"),
PLAYMODE_NOT_SUPPORTED(712, "The specified play mode is not supported by the device"),
RECORDQUALITYMODE_NOT_SUPPORTED(713, "The specified record quality mode is not supported by the device"),
ILLEGAL_MIME_TYPE(714, "The specified resource has a MIME-type which is not supported"),
CONTENT_BUSY(715, "The resource is already being played by other means"),
RESOURCE_NOT_FOUND(716, "The specified resource cannot be found in the network"),
INVALID_INSTANCE_ID(718, "The specified instanceID is invalid for this AVTransport");
private int code;
private String description;
AVTransportErrorCode(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static AVTransportErrorCode getByCode(int code) {
for (AVTransportErrorCode errorCode : values()) {
if (errorCode.getCode() == code)
return errorCode;
}
return null;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/AVTransportErrorCode.java | Java | asf20 | 2,926 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.lastchange;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.model.PlayMode;
import org.teleal.cling.support.model.RecordQualityMode;
import org.teleal.cling.support.model.TransportAction;
import org.teleal.cling.support.model.StorageMedium;
import org.teleal.cling.support.lastchange.EventedValue;
import org.teleal.cling.support.lastchange.EventedValueEnum;
import org.teleal.cling.support.lastchange.EventedValueEnumArray;
import org.teleal.cling.support.lastchange.EventedValueString;
import org.teleal.cling.support.lastchange.EventedValueURI;
import org.teleal.cling.support.lastchange.EventedValueUnsignedIntegerFourBytes;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author Christian Bauer
*/
public class AVTransportVariable {
public static Set<Class<? extends EventedValue>> ALL = new HashSet<Class<? extends EventedValue>>() {{
add(TransportState.class);
add(TransportStatus.class);
add(RecordStorageMedium.class);
add(PossibleRecordStorageMedia.class);
add(PossiblePlaybackStorageMedia.class);
add(CurrentPlayMode.class);
add(TransportPlaySpeed.class);
add(RecordMediumWriteStatus.class);
add(CurrentRecordQualityMode.class);
add(PossibleRecordQualityModes.class);
add(NumberOfTracks.class);
add(CurrentTrack.class);
add(CurrentTrackDuration.class);
add(CurrentMediaDuration.class);
add(CurrentTrackMetaData.class);
add(CurrentTrackURI.class);
add(AVTransportURI.class);
add(NextAVTransportURI.class);
add(AVTransportURIMetaData.class);
add(NextAVTransportURIMetaData.class);
add(CurrentTransportActions.class);
}};
public static class TransportState extends EventedValueEnum<org.teleal.cling.support.model.TransportState> {
public TransportState(org.teleal.cling.support.model.TransportState avTransportState) {
super(avTransportState);
}
public TransportState(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected org.teleal.cling.support.model.TransportState enumValueOf(String s) {
return org.teleal.cling.support.model.TransportState.valueOf(s);
}
}
public static class TransportStatus extends EventedValueEnum<org.teleal.cling.support.model.TransportStatus> {
public TransportStatus(org.teleal.cling.support.model.TransportStatus transportStatus) {
super(transportStatus);
}
public TransportStatus(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected org.teleal.cling.support.model.TransportStatus enumValueOf(String s) {
return org.teleal.cling.support.model.TransportStatus.valueOf(s);
}
}
public static class RecordStorageMedium extends EventedValueEnum<StorageMedium> {
public RecordStorageMedium(StorageMedium storageMedium) {
super(storageMedium);
}
public RecordStorageMedium(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected StorageMedium enumValueOf(String s) {
return StorageMedium.valueOf(s);
}
}
public static class PossibleRecordStorageMedia extends EventedValueEnumArray<StorageMedium> {
public PossibleRecordStorageMedia(StorageMedium[] e) {
super(e);
}
public PossibleRecordStorageMedia(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected StorageMedium[] enumValueOf(String[] names) {
List<StorageMedium> list = new ArrayList();
for (String s : names) {
list.add(StorageMedium.valueOf(s));
}
return list.toArray(new StorageMedium[list.size()]);
}
}
public static class PossiblePlaybackStorageMedia extends PossibleRecordStorageMedia {
public PossiblePlaybackStorageMedia(StorageMedium[] e) {
super(e);
}
public PossiblePlaybackStorageMedia(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class CurrentPlayMode extends EventedValueEnum<PlayMode> {
public CurrentPlayMode(PlayMode playMode) {
super(playMode);
}
public CurrentPlayMode(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected PlayMode enumValueOf(String s) {
return PlayMode.valueOf(s);
}
}
public static class TransportPlaySpeed extends EventedValueString {
public TransportPlaySpeed(String value) {
super(value);
}
public TransportPlaySpeed(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class RecordMediumWriteStatus extends EventedValueEnum<org.teleal.cling.support.model.RecordMediumWriteStatus> {
public RecordMediumWriteStatus(org.teleal.cling.support.model.RecordMediumWriteStatus recordMediumWriteStatus) {
super(recordMediumWriteStatus);
}
public RecordMediumWriteStatus(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected org.teleal.cling.support.model.RecordMediumWriteStatus enumValueOf(String s) {
return org.teleal.cling.support.model.RecordMediumWriteStatus.valueOf(s);
}
}
public static class CurrentRecordQualityMode extends EventedValueEnum<RecordQualityMode> {
public CurrentRecordQualityMode(RecordQualityMode recordQualityMode) {
super(recordQualityMode);
}
public CurrentRecordQualityMode(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected RecordQualityMode enumValueOf(String s) {
return RecordQualityMode.valueOf(s);
}
}
public static class PossibleRecordQualityModes extends EventedValueEnumArray<RecordQualityMode> {
public PossibleRecordQualityModes(RecordQualityMode[] e) {
super(e);
}
public PossibleRecordQualityModes(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected RecordQualityMode[] enumValueOf(String[] names) {
List<RecordQualityMode> list = new ArrayList();
for (String s : names) {
list.add(RecordQualityMode.valueOf(s));
}
return list.toArray(new RecordQualityMode[list.size()]);
}
}
public static class NumberOfTracks extends EventedValueUnsignedIntegerFourBytes {
public NumberOfTracks(UnsignedIntegerFourBytes value) {
super(value);
}
public NumberOfTracks(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class CurrentTrack extends EventedValueUnsignedIntegerFourBytes {
public CurrentTrack(UnsignedIntegerFourBytes value) {
super(value);
}
public CurrentTrack(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class CurrentTrackDuration extends EventedValueString {
public CurrentTrackDuration(String value) {
super(value);
}
public CurrentTrackDuration(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class CurrentMediaDuration extends EventedValueString {
public CurrentMediaDuration(String value) {
super(value);
}
public CurrentMediaDuration(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class CurrentTrackMetaData extends EventedValueString {
public CurrentTrackMetaData(String value) {
super(value);
}
public CurrentTrackMetaData(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class CurrentTrackURI extends EventedValueURI {
public CurrentTrackURI(URI value) {
super(value);
}
public CurrentTrackURI(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class AVTransportURI extends EventedValueURI {
public AVTransportURI(URI value) {
super(value);
}
public AVTransportURI(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class NextAVTransportURI extends EventedValueURI {
public NextAVTransportURI(URI value) {
super(value);
}
public NextAVTransportURI(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class AVTransportURIMetaData extends EventedValueString {
public AVTransportURIMetaData(String value) {
super(value);
}
public AVTransportURIMetaData(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class NextAVTransportURIMetaData extends EventedValueString {
public NextAVTransportURIMetaData(String value) {
super(value);
}
public NextAVTransportURIMetaData(Map.Entry<String, String>[] attributes) {
super(attributes);
}
}
public static class CurrentTransportActions extends EventedValueEnumArray<TransportAction>{
public CurrentTransportActions(TransportAction[] e) {
super(e);
}
public CurrentTransportActions(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected TransportAction[] enumValueOf(String[] names) {
if (names == null) return new TransportAction[0];
List<TransportAction> list = new ArrayList();
for (String s : names) {
list.add(TransportAction.valueOf(s));
}
return list.toArray(new TransportAction[list.size()]);
}
}
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/lastchange/AVTransportVariable.java | Java | asf20 | 11,290 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.lastchange;
import org.teleal.cling.model.ModelUtil;
import org.teleal.cling.support.lastchange.EventedValue;
import org.teleal.cling.support.lastchange.LastChangeParser;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import java.util.Set;
/**
* @author Christian Bauer
*/
public class AVTransportLastChangeParser extends LastChangeParser {
public static final String NAMESPACE_URI = "urn:schemas-upnp-org:metadata-1-0/AVT/";
public static final String SCHEMA_RESOURCE = "org/teleal/cling/support/avtransport/metadata-1.0-avt.xsd";
@Override
protected String getNamespace() {
return NAMESPACE_URI;
}
@Override
protected Source[] getSchemaSources() {
// TODO: Android 2.2 has a broken SchemaFactory, we can't validate
// http://code.google.com/p/android/issues/detail?id=9491&q=schemafactory&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
if (!ModelUtil.ANDROID_RUNTIME) {
return new Source[]{new StreamSource(
Thread.currentThread().getContextClassLoader().getResourceAsStream(SCHEMA_RESOURCE)
)};
}
return null;
}
@Override
protected Set<Class<? extends EventedValue>> getEventedVariables() {
return AVTransportVariable.ALL;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/lastchange/AVTransportLastChangeParser.java | Java | asf20 | 2,095 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.impl;
import org.teleal.cling.support.avtransport.impl.state.AbstractState;
import org.teleal.cling.support.model.SeekMode;
import org.teleal.common.statemachine.StateMachine;
import java.net.URI;
public interface AVTransportStateMachine extends StateMachine<AbstractState> {
public abstract void setTransportURI(URI uri, String uriMetaData);
public abstract void setNextTransportURI(URI uri, String uriMetaData);
public abstract void stop();
public abstract void play(String speed);
public abstract void pause();
public abstract void record();
public abstract void seek(SeekMode unit, String target);
public abstract void next();
public abstract void previous();
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/impl/AVTransportStateMachine.java | Java | asf20 | 1,477 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.impl;
import org.teleal.cling.model.ModelUtil;
import org.teleal.cling.model.types.ErrorCode;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.avtransport.AVTransportErrorCode;
import org.teleal.cling.support.avtransport.AVTransportException;
import org.teleal.cling.support.avtransport.AbstractAVTransportService;
import org.teleal.cling.support.avtransport.impl.state.AbstractState;
import org.teleal.cling.support.lastchange.LastChange;
import org.teleal.cling.support.model.AVTransport;
import org.teleal.cling.support.model.DeviceCapabilities;
import org.teleal.cling.support.model.MediaInfo;
import org.teleal.cling.support.model.PlayMode;
import org.teleal.cling.support.model.PositionInfo;
import org.teleal.cling.support.model.RecordQualityMode;
import org.teleal.cling.support.model.SeekMode;
import org.teleal.cling.support.model.StorageMedium;
import org.teleal.cling.support.model.TransportAction;
import org.teleal.cling.support.model.TransportInfo;
import org.teleal.cling.support.model.TransportSettings;
import org.teleal.common.statemachine.StateMachineBuilder;
import org.teleal.common.statemachine.TransitionException;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
/**
* State-machine based implementation of AVTransport service.
* <p>
* One logical AVTransport is represented by:
* </p>
* <ul>
* <li>
* One {@link org.teleal.cling.support.avtransport.impl.AVTransportStateMachine}
* instance that accepts the action method call as a proxy.
* </li>
* <li>
* Each state machine holds several instances of
* {@link org.teleal.cling.support.avtransport.impl.state.AbstractState}, created on
* instantation of the state machine. The "current" state will be the target of
* the action call. It is the state implementation that decides how to handle the
* call and what the next state is after a possible transition.
* </li>
* <li>
* Each state has a reference to an implementation of
* {@link org.teleal.cling.support.model.AVTransport}, where the state can hold
* information about well, the state.
* </li>
* </ul>
* <p>
* Simplified, this means that each AVTransport instance ID is typically handled by
* one state machine, and the internal state of that machine is stored in an
* <code>AVTransport</code>.
* </p>
* <p>
* Override the {@link #createTransport(org.teleal.cling.model.types.UnsignedIntegerFourBytes, org.teleal.cling.support.lastchange.LastChange)}
* method to utilize a subclass of <code>AVTransport</code> as your internal state holder.
* </p>
*
* @author Christian Bauer
*/
public class AVTransportService<T extends AVTransport> extends AbstractAVTransportService {
final private static Logger log = Logger.getLogger(AVTransportService.class.getName());
final private Map<Long, AVTransportStateMachine> stateMachines = new ConcurrentHashMap();
final Class<? extends AVTransportStateMachine> stateMachineDefinition;
final Class<? extends AbstractState> initialState;
final Class<? extends AVTransport> transportClass;
public AVTransportService(Class<? extends AVTransportStateMachine> stateMachineDefinition,
Class<? extends AbstractState> initialState) {
this(stateMachineDefinition, initialState, (Class<T>)AVTransport.class);
}
public AVTransportService(Class<? extends AVTransportStateMachine> stateMachineDefinition,
Class<? extends AbstractState> initialState,
Class<T> transportClass) {
this.stateMachineDefinition = stateMachineDefinition;
this.initialState = initialState;
this.transportClass = transportClass;
}
public void setAVTransportURI(UnsignedIntegerFourBytes instanceId,
String currentURI,
String currentURIMetaData) throws AVTransportException {
URI uri;
try {
uri = new URI(currentURI);
} catch (Exception ex) {
throw new AVTransportException(
ErrorCode.INVALID_ARGS, "CurrentURI can not be null or malformed"
);
}
try {
AVTransportStateMachine transportStateMachine = findStateMachine(instanceId, true);
transportStateMachine.setTransportURI(uri, currentURIMetaData);
} catch (TransitionException ex) {
throw new AVTransportException(AVTransportErrorCode.TRANSITION_NOT_AVAILABLE, ex.getMessage());
}
}
public void setNextAVTransportURI(UnsignedIntegerFourBytes instanceId,
String nextURI,
String nextURIMetaData) throws AVTransportException {
URI uri;
try {
uri = new URI(nextURI);
} catch (Exception ex) {
throw new AVTransportException(
ErrorCode.INVALID_ARGS, "NextURI can not be null or malformed"
);
}
try {
AVTransportStateMachine transportStateMachine = findStateMachine(instanceId, true);
transportStateMachine.setNextTransportURI(uri, nextURIMetaData);
} catch (TransitionException ex) {
throw new AVTransportException(AVTransportErrorCode.TRANSITION_NOT_AVAILABLE, ex.getMessage());
}
}
public void setPlayMode(UnsignedIntegerFourBytes instanceId, String newPlayMode) throws AVTransportException {
AVTransport transport = findStateMachine(instanceId).getCurrentState().getTransport();
try {
transport.setTransportSettings(
new TransportSettings(
PlayMode.valueOf(newPlayMode),
transport.getTransportSettings().getRecQualityMode()
)
);
} catch (IllegalArgumentException ex) {
throw new AVTransportException(
AVTransportErrorCode.PLAYMODE_NOT_SUPPORTED, "Unsupported play mode: " + newPlayMode
);
}
}
public void setRecordQualityMode(UnsignedIntegerFourBytes instanceId, String newRecordQualityMode) throws AVTransportException {
AVTransport transport = findStateMachine(instanceId).getCurrentState().getTransport();
try {
transport.setTransportSettings(
new TransportSettings(
transport.getTransportSettings().getPlayMode(),
RecordQualityMode.valueOrExceptionOf(newRecordQualityMode)
)
);
} catch (IllegalArgumentException ex) {
throw new AVTransportException(
AVTransportErrorCode.RECORDQUALITYMODE_NOT_SUPPORTED, "Unsupported record quality mode: " + newRecordQualityMode
);
}
}
public MediaInfo getMediaInfo(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
return findStateMachine(instanceId).getCurrentState().getTransport().getMediaInfo();
}
public TransportInfo getTransportInfo(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
return findStateMachine(instanceId).getCurrentState().getTransport().getTransportInfo();
}
public PositionInfo getPositionInfo(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
return findStateMachine(instanceId).getCurrentState().getTransport().getPositionInfo();
}
public DeviceCapabilities getDeviceCapabilities(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
return findStateMachine(instanceId).getCurrentState().getTransport().getDeviceCapabilities();
}
public TransportSettings getTransportSettings(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
return findStateMachine(instanceId).getCurrentState().getTransport().getTransportSettings();
}
public String getCurrentTransportActions(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
AVTransportStateMachine stateMachine = findStateMachine(instanceId);
try {
TransportAction[] actions = stateMachine.getCurrentState().getCurrentTransportActions();
return ModelUtil.toCommaSeparatedList(actions);
} catch (TransitionException ex) {
return ""; // TODO: Empty string is not defined in spec but seems reasonable for no available action?
}
}
public void stop(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
try {
findStateMachine(instanceId).stop();
} catch (TransitionException ex) {
throw new AVTransportException(AVTransportErrorCode.TRANSITION_NOT_AVAILABLE, ex.getMessage());
}
}
public void play(UnsignedIntegerFourBytes instanceId, String speed) throws AVTransportException {
try {
findStateMachine(instanceId).play(speed);
} catch (TransitionException ex) {
throw new AVTransportException(AVTransportErrorCode.TRANSITION_NOT_AVAILABLE, ex.getMessage());
}
}
public void pause(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
try {
findStateMachine(instanceId).pause();
} catch (TransitionException ex) {
throw new AVTransportException(AVTransportErrorCode.TRANSITION_NOT_AVAILABLE, ex.getMessage());
}
}
public void record(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
try {
findStateMachine(instanceId).record();
} catch (TransitionException ex) {
throw new AVTransportException(AVTransportErrorCode.TRANSITION_NOT_AVAILABLE, ex.getMessage());
}
}
public void seek(UnsignedIntegerFourBytes instanceId, String unit, String target) throws AVTransportException {
SeekMode seekMode;
try {
seekMode = SeekMode.valueOrExceptionOf(unit);
} catch (IllegalArgumentException ex) {
throw new AVTransportException(
AVTransportErrorCode.SEEKMODE_NOT_SUPPORTED, "Unsupported seek mode: " + unit
);
}
try {
findStateMachine(instanceId).seek(seekMode, target);
} catch (TransitionException ex) {
throw new AVTransportException(AVTransportErrorCode.TRANSITION_NOT_AVAILABLE, ex.getMessage());
}
}
public void next(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
try {
findStateMachine(instanceId).next();
} catch (TransitionException ex) {
throw new AVTransportException(AVTransportErrorCode.TRANSITION_NOT_AVAILABLE, ex.getMessage());
}
}
public void previous(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
try {
findStateMachine(instanceId).previous();
} catch (TransitionException ex) {
throw new AVTransportException(AVTransportErrorCode.TRANSITION_NOT_AVAILABLE, ex.getMessage());
}
}
protected AVTransportStateMachine findStateMachine(UnsignedIntegerFourBytes instanceId) throws AVTransportException {
return findStateMachine(instanceId, true);
}
protected AVTransportStateMachine findStateMachine(UnsignedIntegerFourBytes instanceId, boolean createDefaultTransport) throws AVTransportException {
synchronized (stateMachines) {
long id = instanceId.getValue();
AVTransportStateMachine stateMachine = stateMachines.get(id);
if (stateMachine == null && id == 0 && createDefaultTransport) {
log.fine("Creating default transport instance with ID '0'");
stateMachine = createStateMachine(instanceId);
stateMachines.put(id, stateMachine);
} else if (stateMachine == null) {
throw new AVTransportException(AVTransportErrorCode.INVALID_INSTANCE_ID);
}
log.fine("Found transport control with ID '" + id + "'");
return stateMachine;
}
}
protected AVTransportStateMachine createStateMachine(UnsignedIntegerFourBytes instanceId) {
// Create a proxy that delegates all calls to the right state implementation, working on the T state
return StateMachineBuilder.build(
stateMachineDefinition,
initialState,
new Class[]{transportClass},
new Object[]{createTransport(instanceId, getLastChange())}
);
}
protected AVTransport createTransport(UnsignedIntegerFourBytes instanceId, LastChange lastChange) {
return new AVTransport(instanceId, lastChange, StorageMedium.NETWORK);
}
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/impl/AVTransportService.java | Java | asf20 | 13,631 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.impl.state;
import org.teleal.cling.support.avtransport.lastchange.AVTransportVariable;
import org.teleal.cling.support.model.AVTransport;
import org.teleal.cling.support.model.TransportAction;
import org.teleal.cling.support.model.TransportInfo;
import org.teleal.cling.support.model.TransportState;
import java.net.URI;
import java.util.logging.Logger;
/**
* @author Christian Bauer
*/
public abstract class PausedPlay<T extends AVTransport> extends AbstractState {
final private static Logger log = Logger.getLogger(PausedPlay.class.getName());
public PausedPlay(T transport) {
super(transport);
}
public void onEntry() {
log.fine("Setting transport state to PAUSED_PLAYBACK");
getTransport().setTransportInfo(
new TransportInfo(
TransportState.PAUSED_PLAYBACK,
getTransport().getTransportInfo().getCurrentTransportStatus(),
getTransport().getTransportInfo().getCurrentSpeed()
)
);
getTransport().getLastChange().setEventedValue(
getTransport().getInstanceId(),
new AVTransportVariable.TransportState(TransportState.PAUSED_PLAYBACK),
new AVTransportVariable.CurrentTransportActions(getCurrentTransportActions())
);
}
public abstract Class<? extends AbstractState> setTransportURI(URI uri, String metaData);
public abstract Class<? extends AbstractState> stop();
public abstract Class<? extends AbstractState> play(String speed);
public TransportAction[] getCurrentTransportActions() {
return new TransportAction[] {
TransportAction.Stop,
TransportAction.Play
};
}
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/impl/state/PausedPlay.java | Java | asf20 | 2,538 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.impl.state;
import org.teleal.cling.support.avtransport.lastchange.AVTransportVariable;
import org.teleal.cling.support.model.AVTransport;
import org.teleal.cling.support.model.TransportAction;
import org.teleal.cling.support.model.TransportInfo;
import org.teleal.cling.support.model.TransportState;
import java.net.URI;
import java.util.logging.Logger;
/**
* @author Christian Bauer
*/
public abstract class NoMediaPresent<T extends AVTransport> extends AbstractState<T> {
final private static Logger log = Logger.getLogger(Stopped.class.getName());
public NoMediaPresent(T transport) {
super(transport);
}
public void onEntry() {
log.fine("Setting transport state to NO_MEDIA_PRESENT");
getTransport().setTransportInfo(
new TransportInfo(
TransportState.NO_MEDIA_PRESENT,
getTransport().getTransportInfo().getCurrentTransportStatus(),
getTransport().getTransportInfo().getCurrentSpeed()
)
);
getTransport().getLastChange().setEventedValue(
getTransport().getInstanceId(),
new AVTransportVariable.TransportState(TransportState.NO_MEDIA_PRESENT),
new AVTransportVariable.CurrentTransportActions(getCurrentTransportActions())
);
}
public abstract Class<? extends AbstractState> setTransportURI(URI uri, String metaData);
public TransportAction[] getCurrentTransportActions() {
return new TransportAction[] {
TransportAction.Stop
};
}
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/impl/state/NoMediaPresent.java | Java | asf20 | 2,380 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.impl.state;
import org.teleal.cling.support.avtransport.lastchange.AVTransportVariable;
import org.teleal.cling.support.model.AVTransport;
import org.teleal.cling.support.model.SeekMode;
import org.teleal.cling.support.model.TransportAction;
import org.teleal.cling.support.model.TransportInfo;
import org.teleal.cling.support.model.TransportState;
import java.net.URI;
import java.util.logging.Logger;
/**
* @author Christian Bauer
*/
public abstract class Stopped<T extends AVTransport> extends AbstractState {
final private static Logger log = Logger.getLogger(Stopped.class.getName());
public Stopped(T transport) {
super(transport);
}
public void onEntry() {
log.fine("Setting transport state to STOPPED");
getTransport().setTransportInfo(
new TransportInfo(
TransportState.STOPPED,
getTransport().getTransportInfo().getCurrentTransportStatus(),
getTransport().getTransportInfo().getCurrentSpeed()
)
);
getTransport().getLastChange().setEventedValue(
getTransport().getInstanceId(),
new AVTransportVariable.TransportState(TransportState.STOPPED),
new AVTransportVariable.CurrentTransportActions(getCurrentTransportActions())
);
}
public abstract Class<? extends AbstractState> setTransportURI(URI uri, String metaData);
public abstract Class<? extends AbstractState> stop();
public abstract Class<? extends AbstractState> play(String speed);
public abstract Class<? extends AbstractState> next();
public abstract Class<? extends AbstractState> previous();
public abstract Class<? extends AbstractState> seek(SeekMode unit, String target);
public TransportAction[] getCurrentTransportActions() {
return new TransportAction[] {
TransportAction.Stop,
TransportAction.Play,
TransportAction.Next,
TransportAction.Previous,
TransportAction.Seek
};
}
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/impl/state/Stopped.java | Java | asf20 | 2,879 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.impl.state;
import org.teleal.cling.support.model.AVTransport;
import org.teleal.cling.support.model.TransportAction;
/**
*
*/
public abstract class AbstractState<T extends AVTransport> {
private T transport;
public AbstractState(T transport) {
this.transport = transport;
}
public T getTransport() {
return transport;
}
public abstract TransportAction[] getCurrentTransportActions();
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/impl/state/AbstractState.java | Java | asf20 | 1,206 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.impl.state;
import org.teleal.cling.support.avtransport.lastchange.AVTransportVariable;
import org.teleal.cling.support.model.AVTransport;
import org.teleal.cling.support.model.SeekMode;
import org.teleal.cling.support.model.TransportAction;
import org.teleal.cling.support.model.TransportInfo;
import org.teleal.cling.support.model.TransportState;
import java.net.URI;
import java.util.logging.Logger;
/**
* @author Christian Bauer
*/
public abstract class Playing<T extends AVTransport> extends AbstractState {
final private static Logger log = Logger.getLogger(Playing.class.getName());
public Playing(T transport) {
super(transport);
}
public void onEntry() {
log.fine("Setting transport state to PLAYING");
getTransport().setTransportInfo(
new TransportInfo(
TransportState.PLAYING,
getTransport().getTransportInfo().getCurrentTransportStatus(),
getTransport().getTransportInfo().getCurrentSpeed()
)
);
getTransport().getLastChange().setEventedValue(
getTransport().getInstanceId(),
new AVTransportVariable.TransportState(TransportState.PLAYING),
new AVTransportVariable.CurrentTransportActions(getCurrentTransportActions())
);
}
public abstract Class<? extends AbstractState> setTransportURI(URI uri, String metaData);
public abstract Class<? extends AbstractState> stop();
public abstract Class<? extends AbstractState> play(String speed);
public abstract Class<? extends AbstractState> pause();
public abstract Class<? extends AbstractState> next();
public abstract Class<? extends AbstractState> previous();
public abstract Class<? extends AbstractState> seek(SeekMode unit, String target);
public TransportAction[] getCurrentTransportActions() {
return new TransportAction[] {
TransportAction.Stop,
TransportAction.Play,
TransportAction.Pause,
TransportAction.Next,
TransportAction.Previous,
TransportAction.Seek
};
}
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/impl/state/Playing.java | Java | asf20 | 2,978 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport;
import org.teleal.cling.model.action.ActionException;
import org.teleal.cling.model.types.ErrorCode;
/**
*
*/
public class AVTransportException extends ActionException {
public AVTransportException(int errorCode, String message) {
super(errorCode, message);
}
public AVTransportException(int errorCode, String message, Throwable cause) {
super(errorCode, message, cause);
}
public AVTransportException(ErrorCode errorCode, String message) {
super(errorCode, message);
}
public AVTransportException(ErrorCode errorCode) {
super(errorCode);
}
public AVTransportException(AVTransportErrorCode errorCode, String message) {
super(errorCode.getCode(), errorCode.getDescription() + ". " + message + ".");
}
public AVTransportException(AVTransportErrorCode errorCode) {
super(errorCode.getCode(), errorCode.getDescription());
}
}
| zzh84615-mycode | src/org/teleal/cling/support/avtransport/AVTransportException.java | Java | asf20 | 1,699 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import java.util.logging.Logger;
/**
*
* @author Christian Bauer
*/
public abstract class Stop extends ActionCallback {
private static Logger log = Logger.getLogger(Stop.class.getName());
public Stop(Service service) {
this(new UnsignedIntegerFourBytes(0), service);
}
public Stop(UnsignedIntegerFourBytes instanceId, Service service) {
super(new ActionInvocation(service.getAction("Stop")));
getActionInvocation().setInput("InstanceID", instanceId);
}
@Override
public void success(ActionInvocation invocation) {
log.fine("Execution successful");
}
} | zzh84615-mycode | src/org/teleal/cling/support/avtransport/callback/Stop.java | Java | asf20 | 1,619 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import java.util.logging.Logger;
/**
*
* @author Christian Bauer
*/
public abstract class Play extends ActionCallback {
private static Logger log = Logger.getLogger(Play.class.getName());
public Play(Service service) {
this(new UnsignedIntegerFourBytes(0), service, "1");
}
public Play(Service service, String speed) {
this(new UnsignedIntegerFourBytes(0), service, speed);
}
public Play(UnsignedIntegerFourBytes instanceId, Service service) {
this(instanceId, service, "1");
}
public Play(UnsignedIntegerFourBytes instanceId, Service service, String speed) {
super(new ActionInvocation(service.getAction("Play")));
getActionInvocation().setInput("InstanceID", instanceId);
getActionInvocation().setInput("Speed", speed);
}
@Override
public void success(ActionInvocation invocation) {
log.fine("Execution successful");
}
} | zzh84615-mycode | src/org/teleal/cling/support/avtransport/callback/Play.java | Java | asf20 | 1,932 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.model.DeviceCapabilities;
import java.util.logging.Logger;
/**
*
* @author Christian Bauer
*/
public abstract class GetDeviceCapabilities extends ActionCallback {
private static Logger log = Logger.getLogger(GetDeviceCapabilities.class.getName());
public GetDeviceCapabilities(Service service) {
this(new UnsignedIntegerFourBytes(0), service);
}
public GetDeviceCapabilities(UnsignedIntegerFourBytes instanceId, Service service) {
super(new ActionInvocation(service.getAction("GetDeviceCapabilities")));
getActionInvocation().setInput("InstanceID", instanceId);
}
public void success(ActionInvocation invocation) {
DeviceCapabilities caps = new DeviceCapabilities(invocation.getOutputMap());
received(invocation, caps);
}
public abstract void received(ActionInvocation actionInvocation, DeviceCapabilities caps);
} | zzh84615-mycode | src/org/teleal/cling/support/avtransport/callback/GetDeviceCapabilities.java | Java | asf20 | 1,924 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.model.SeekMode;
import java.util.logging.Logger;
/**
*
* @author Christian Bauer
*/
public abstract class Seek extends ActionCallback {
private static Logger log = Logger.getLogger(Seek.class.getName());
public Seek(Service service, String relativeTimeTarget) {
this(new UnsignedIntegerFourBytes(0), service, SeekMode.REL_TIME, relativeTimeTarget);
}
public Seek(UnsignedIntegerFourBytes instanceId, Service service, String relativeTimeTarget) {
this(instanceId, service, SeekMode.REL_TIME, relativeTimeTarget);
}
public Seek(Service service, SeekMode mode, String target) {
this(new UnsignedIntegerFourBytes(0), service, mode, target);
}
public Seek(UnsignedIntegerFourBytes instanceId, Service service, SeekMode mode, String target) {
super(new ActionInvocation(service.getAction("Seek")));
getActionInvocation().setInput("InstanceID", instanceId);
getActionInvocation().setInput("Unit", mode.name());
getActionInvocation().setInput("Target", target);
}
@Override
public void success(ActionInvocation invocation) {
log.fine("Execution successful");
}
} | zzh84615-mycode | src/org/teleal/cling/support/avtransport/callback/Seek.java | Java | asf20 | 2,204 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.model.DeviceCapabilities;
import org.teleal.cling.support.model.TransportAction;
import java.util.logging.Logger;
/**
* @author Christian Bauer
*/
public abstract class GetCurrentTransportActions extends ActionCallback {
private static Logger log = Logger.getLogger(GetCurrentTransportActions.class.getName());
public GetCurrentTransportActions(Service service) {
this(new UnsignedIntegerFourBytes(0), service);
}
public GetCurrentTransportActions(UnsignedIntegerFourBytes instanceId, Service service) {
super(new ActionInvocation(service.getAction("GetCurrentTransportActions")));
getActionInvocation().setInput("InstanceID", instanceId);
}
public void success(ActionInvocation invocation) {
String actionsString = (String)invocation.getOutput("Actions").getValue();
received(invocation, TransportAction.valueOfCommaSeparatedList(actionsString));
}
public abstract void received(ActionInvocation actionInvocation, TransportAction[] actions);
} | zzh84615-mycode | src/org/teleal/cling/support/avtransport/callback/GetCurrentTransportActions.java | Java | asf20 | 2,053 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.controlpoint.ControlPoint;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.message.UpnpResponse;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import java.util.logging.Logger;
/**
*
* @author Christian Bauer
*/
public abstract class Pause extends ActionCallback {
private static Logger log = Logger.getLogger(Pause.class.getName());
protected Pause(ActionInvocation actionInvocation, ControlPoint controlPoint) {
super(actionInvocation, controlPoint);
}
protected Pause(ActionInvocation actionInvocation) {
super(actionInvocation);
}
public Pause(Service service) {
this(new UnsignedIntegerFourBytes(0), service);
}
public Pause(UnsignedIntegerFourBytes instanceId, Service service) {
super(new ActionInvocation(service.getAction("Pause")));
getActionInvocation().setInput("InstanceID", instanceId);
}
@Override
public void success(ActionInvocation invocation) {
log.fine("Execution successful");
}
} | zzh84615-mycode | src/org/teleal/cling/support/avtransport/callback/Pause.java | Java | asf20 | 1,962 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.model.TransportInfo;
import java.util.logging.Logger;
/**
*
* @author Christian Bauer
*/
public abstract class GetTransportInfo extends ActionCallback {
private static Logger log = Logger.getLogger(GetTransportInfo.class.getName());
public GetTransportInfo(Service service) {
this(new UnsignedIntegerFourBytes(0), service);
}
public GetTransportInfo(UnsignedIntegerFourBytes instanceId, Service service) {
super(new ActionInvocation(service.getAction("GetTransportInfo")));
getActionInvocation().setInput("InstanceID", instanceId);
}
public void success(ActionInvocation invocation) {
TransportInfo transportInfo = new TransportInfo(invocation.getOutputMap());
received(invocation, transportInfo);
}
public abstract void received(ActionInvocation invocation, TransportInfo transportInfo);
} | zzh84615-mycode | src/org/teleal/cling/support/avtransport/callback/GetTransportInfo.java | Java | asf20 | 1,900 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import java.util.logging.Logger;
/**
* @author Christian Bauer
*/
public abstract class SetAVTransportURI extends ActionCallback {
private static Logger log = Logger.getLogger(SetAVTransportURI.class.getName());
public SetAVTransportURI(Service service, String uri) {
this(new UnsignedIntegerFourBytes(0), service, uri, null);
}
public SetAVTransportURI(Service service, String uri, String metadata) {
this(new UnsignedIntegerFourBytes(0), service, uri, metadata);
}
public SetAVTransportURI(UnsignedIntegerFourBytes instanceId, Service service, String uri) {
this(instanceId, service, uri, null);
}
public SetAVTransportURI(UnsignedIntegerFourBytes instanceId, Service service, String uri, String metadata) {
super(new ActionInvocation(service.getAction("SetAVTransportURI")));
log.fine("Creating SetAVTransportURI action for URI: " + uri);
getActionInvocation().setInput("InstanceID", instanceId);
getActionInvocation().setInput("CurrentURI", uri);
getActionInvocation().setInput("CurrentURIMetaData", metadata);
}
@Override
public void success(ActionInvocation invocation) {
log.fine("Execution successful");
}
} | zzh84615-mycode | src/org/teleal/cling/support/avtransport/callback/SetAVTransportURI.java | Java | asf20 | 2,240 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.model.MediaInfo;
import java.util.logging.Logger;
/**
*
* @author Christian Bauer
*/
public abstract class GetMediaInfo extends ActionCallback {
private static Logger log = Logger.getLogger(GetMediaInfo.class.getName());
public GetMediaInfo(Service service) {
this(new UnsignedIntegerFourBytes(0), service);
}
public GetMediaInfo(UnsignedIntegerFourBytes instanceId, Service service) {
super(new ActionInvocation(service.getAction("GetMediaInfo")));
getActionInvocation().setInput("InstanceID", instanceId);
}
public void success(ActionInvocation invocation) {
MediaInfo mediaInfo = new MediaInfo(invocation.getOutputMap());
received(invocation, mediaInfo);
}
public abstract void received(ActionInvocation invocation, MediaInfo mediaInfo);
} | zzh84615-mycode | src/org/teleal/cling/support/avtransport/callback/GetMediaInfo.java | Java | asf20 | 1,852 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.avtransport.callback;
import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.model.PositionInfo;
import java.util.logging.Logger;
/**
*
* @author Christian Bauer
*/
public abstract class GetPositionInfo extends ActionCallback {
private static Logger log = Logger.getLogger(GetPositionInfo.class.getName());
public GetPositionInfo(Service service) {
this(new UnsignedIntegerFourBytes(0), service);
}
public GetPositionInfo(UnsignedIntegerFourBytes instanceId, Service service) {
super(new ActionInvocation(service.getAction("GetPositionInfo")));
getActionInvocation().setInput("InstanceID", instanceId);
}
public void success(ActionInvocation invocation) {
PositionInfo positionInfo = new PositionInfo(invocation.getOutputMap());
received(invocation, positionInfo);
}
public abstract void received(ActionInvocation invocation, PositionInfo positionInfo);
} | zzh84615-mycode | src/org/teleal/cling/support/avtransport/callback/GetPositionInfo.java | Java | asf20 | 1,888 |
/*
* Copyright (C) 2011 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.types.Datatype;
import java.util.Map;
/**
* @author Christian Bauer
*/
public class EventedValueShort extends EventedValue<Short> {
public EventedValueShort(Short value) {
super(value);
}
public EventedValueShort(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected Datatype getDatatype() {
return Datatype.Builtin.I2_SHORT.getDatatype();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/EventedValueShort.java | Java | asf20 | 1,233 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.types.Datatype;
import org.teleal.cling.model.types.StringDatatype;
import java.util.Map;
/**
* @author Christian Bauer
*/
public class EventedValueString extends EventedValue<String> {
public EventedValueString(String value) {
super(value);
}
public EventedValueString(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected Datatype getDatatype() {
return Datatype.Builtin.STRING.getDatatype();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/EventedValueString.java | Java | asf20 | 1,289 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.types.Datatype;
import org.teleal.cling.model.types.InvalidValueException;
import java.util.Map;
/**
* @author Christian Bauer
*/
public abstract class EventedValueEnum<E extends Enum> extends EventedValue<E> {
public EventedValueEnum(E e) {
super(e);
}
public EventedValueEnum(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected E valueOf(String s) throws InvalidValueException {
return enumValueOf(s);
}
protected abstract E enumValueOf(String s);
@Override
public String toString() {
return getValue().name();
}
@Override
protected Datatype getDatatype() {
return null;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/EventedValueEnum.java | Java | asf20 | 1,515 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.types.Datatype;
import org.teleal.cling.model.types.InvalidValueException;
import org.teleal.cling.support.shared.AbstractMap;
import java.util.Map;
public abstract class EventedValue<V> {
final protected V value;
public EventedValue(V value) {
this.value = value;
}
public EventedValue(Map.Entry<String,String>[] attributes) {
try {
this.value = valueOf(attributes);
} catch (InvalidValueException ex) {
throw new RuntimeException(ex);
}
}
public String getName() {
return getClass().getSimpleName();
}
public V getValue() {
return value;
}
public Map.Entry<String, String>[] getAttributes() {
return new Map.Entry[] {
new AbstractMap.SimpleEntry<String, String>("val", toString())
};
}
protected V valueOf(Map.Entry<String,String>[] attributes) throws InvalidValueException {
V v = null;
for (Map.Entry<String, String> attribute : attributes) {
if (attribute.getKey().equals("val")) v = valueOf(attribute.getValue());
}
return v;
}
protected V valueOf(String s) throws InvalidValueException {
return (V)getDatatype().valueOf(s);
}
@Override
public String toString() {
return getDatatype().getString(getValue());
}
abstract protected Datatype getDatatype();
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/EventedValue.java | Java | asf20 | 2,210 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.types.Datatype;
import org.teleal.cling.model.types.UnsignedIntegerTwoBytes;
import java.util.Map;
/**
* @author Christian Bauer
*/
public class EventedValueUnsignedIntegerTwoBytes extends EventedValue<UnsignedIntegerTwoBytes> {
public EventedValueUnsignedIntegerTwoBytes(UnsignedIntegerTwoBytes value) {
super(value);
}
public EventedValueUnsignedIntegerTwoBytes(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected Datatype getDatatype() {
return Datatype.Builtin.UI2.getDatatype();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/EventedValueUnsignedIntegerTwoBytes.java | Java | asf20 | 1,379 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Collects all state changes per logical instance.
* <p>
* This class is supposed to be used on a UPnP state variable field,
* on a RenderingControl or AVTransport service. The service then
* sets evented values whenever its state changes, and periodically
* (e.g. in a background loop) fires the "LastChange" XML content
* through its PropertyChangeSupport. (Where the ServiceManager picks
* it up and sends it to all subscribers.)
* </p>
* <p>
* The event subscriber can use this class to marshall the "LastChange"
* content, when the event XML is received.
* </p>
* <p>
* This class is thread-safe.
* </p>
*
* @author Christian Bauer
*/
public class LastChange {
final private Event event;
final private LastChangeParser parser;
private String previousValue;
public LastChange(String s) {
throw new UnsupportedOperationException("This constructor is only for service binding detection");
}
public LastChange(LastChangeParser parser, Event event) {
this.parser = parser;
this.event = event;
}
public LastChange(LastChangeParser parser) {
this(parser, new Event());
}
public LastChange(LastChangeParser parser, String xml) throws Exception {
if (xml != null && xml.length() > 0) {
this.event = parser.parse(xml);
} else {
this.event = new Event();
}
this.parser = parser;
}
synchronized public void reset() {
previousValue = toString();
event.clear();
}
synchronized public void setEventedValue(int instanceID, EventedValue... ev) {
setEventedValue(new UnsignedIntegerFourBytes(instanceID), ev);
}
synchronized public void setEventedValue(UnsignedIntegerFourBytes instanceID, EventedValue... ev) {
for (EventedValue eventedValue : ev) {
if (eventedValue != null)
event.setEventedValue(instanceID, eventedValue);
}
}
synchronized public UnsignedIntegerFourBytes[] getInstanceIDs() {
List<UnsignedIntegerFourBytes> list = new ArrayList();
for (InstanceID instanceID : event.getInstanceIDs()) {
list.add(instanceID.getId());
}
return list.toArray(new UnsignedIntegerFourBytes[list.size()]);
}
synchronized EventedValue[] getEventedValues(UnsignedIntegerFourBytes instanceID) {
InstanceID inst = event.getInstanceID(instanceID);
return inst != null ? inst.getValues().toArray(new EventedValue[inst.getValues().size()]) : null;
}
synchronized public <EV extends EventedValue> EV getEventedValue(int instanceID, Class<EV> type) {
return getEventedValue(new UnsignedIntegerFourBytes(instanceID), type);
}
synchronized public <EV extends EventedValue> EV getEventedValue(UnsignedIntegerFourBytes id, Class<EV> type) {
return event.getEventedValue(id, type);
}
synchronized public void fire(PropertyChangeSupport propertyChangeSupport) {
String lastChanges = toString();
if (lastChanges != null && lastChanges.length() > 0) {
propertyChangeSupport.firePropertyChange("LastChange", previousValue, lastChanges);
reset();
}
}
@Override
synchronized public String toString() {
if (!event.hasChanges()) return "";
try {
return parser.generate(event);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/LastChange.java | Java | asf20 | 4,452 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.ModelUtil;
import org.teleal.cling.model.types.Datatype;
import org.teleal.cling.model.types.InvalidValueException;
import java.util.Map;
/**
* @author Christian Bauer
*/
public abstract class EventedValueEnumArray<E extends Enum> extends EventedValue<E[]> {
public EventedValueEnumArray(E[] e) {
super(e);
}
public EventedValueEnumArray(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected E[] valueOf(String s) throws InvalidValueException {
return enumValueOf(ModelUtil.fromCommaSeparatedList(s));
}
protected abstract E[] enumValueOf(String[] names);
@Override
public String toString() {
return ModelUtil.toCommaSeparatedList(getValue());
}
@Override
protected Datatype getDatatype() {
return null;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/EventedValueEnumArray.java | Java | asf20 | 1,644 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.XMLUtil;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.shared.AbstractMap;
import org.teleal.common.io.IO;
import org.teleal.common.util.Exceptions;
import org.teleal.common.xml.SAXParser;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.InputStream;
import java.io.StringReader;
import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.teleal.cling.model.XMLUtil.appendNewElement;
/**
* Reads and writes the "LastChange" XML content.
* <p>
* Validates against a schema if the {@link #getSchemaSources()} method
* doesn't return <code>null</code>.
* </p>
*
* @author Christian Bauer
*/
public abstract class LastChangeParser extends SAXParser {
final private static Logger log = Logger.getLogger(LastChangeParser.class.getName());
public enum CONSTANTS {
Event,
InstanceID,
val;
public boolean equals(String s) {
return this.name().equals(s);
}
}
abstract protected String getNamespace();
protected Set<Class<? extends EventedValue>> getEventedVariables() {
return Collections.EMPTY_SET;
}
protected EventedValue createValue(String name, Map.Entry<String, String>[] attributes) throws Exception {
for (Class<? extends EventedValue> evType : getEventedVariables()) {
if (evType.getSimpleName().equals(name)) {
Constructor<? extends EventedValue> ctor = evType.getConstructor(Map.Entry[].class);
return ctor.newInstance(new Object[]{attributes});
}
}
return null;
}
/**
* Uses the current thread's context classloader to read and unmarshall the given resource.
*
* @param resource The resource on the classpath.
* @return The unmarshalled Event model.
* @throws Exception
*/
public Event parseResource(String resource) throws Exception {
InputStream is = null;
try {
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
return parse(IO.readLines(is));
} finally {
if (is != null) is.close();
}
}
public Event parse(String xml) throws Exception {
if (xml == null || xml.length() == 0) {
throw new RuntimeException("Null or empty XML");
}
Event event = new Event();
new RootHandler(event, this);
log.fine("Parsing 'LastChange' event XML content");
parse(new InputSource(new StringReader(xml)));
log.fine("Parsed event with instances IDs: " + event.getInstanceIDs().size());
if (log.isLoggable(Level.FINEST)) {
for (InstanceID instanceID : event.getInstanceIDs()) {
log.finest("InstanceID '" + instanceID.getId() + "' has values: " + instanceID.getValues().size());
for (EventedValue eventedValue : instanceID.getValues()) {
log.finest(eventedValue.getName() + " => " + eventedValue.getValue());
}
}
}
return event;
}
class RootHandler extends SAXParser.Handler<Event> {
RootHandler(Event instance, SAXParser parser) {
super(instance, parser);
}
RootHandler(Event instance) {
super(instance);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
super.startElement(uri, localName, qName, attributes);
if (CONSTANTS.InstanceID.equals(localName)) {
String valAttr = attributes.getValue(CONSTANTS.val.name());
if (valAttr != null) {
InstanceID instanceID = new InstanceID(new UnsignedIntegerFourBytes(valAttr));
getInstance().getInstanceIDs().add(instanceID);
new InstanceIDHandler(instanceID, this);
}
}
}
}
class InstanceIDHandler extends SAXParser.Handler<InstanceID> {
InstanceIDHandler(InstanceID instance, SAXParser.Handler parent) {
super(instance, parent);
}
@Override
public void startElement(String uri, String localName, String qName, final Attributes attributes) throws SAXException {
super.startElement(uri, localName, qName, attributes);
Map.Entry[] attributeMap = new Map.Entry[attributes.getLength()];
for (int i = 0; i < attributeMap.length; i++) {
attributeMap[i] =
new AbstractMap.SimpleEntry<String, String>(
attributes.getLocalName(i),
attributes.getValue(i)
);
}
try {
EventedValue esv = createValue(localName, attributeMap);
if (esv != null)
getInstance().getValues().add(esv);
} catch (Exception ex) {
// Don't exit, just log a warning
log.warning("Error reading event XML, ignoring value: " + Exceptions.unwrap(ex));
}
}
@Override
protected boolean isLastElement(String uri, String localName, String qName) {
return CONSTANTS.InstanceID.equals(localName);
}
}
public String generate(Event event) throws Exception {
return XMLUtil.documentToFragmentString(buildDOM(event));
}
protected Document buildDOM(Event event) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document d = factory.newDocumentBuilder().newDocument();
generateRoot(event, d);
return d;
}
protected void generateRoot(Event event, Document descriptor) {
Element eventElement = descriptor.createElementNS(getNamespace(), CONSTANTS.Event.name());
descriptor.appendChild(eventElement);
generateInstanceIDs(event, descriptor, eventElement);
}
protected void generateInstanceIDs(Event event, Document descriptor, Element rootElement) {
for (InstanceID instanceID : event.getInstanceIDs()) {
if (instanceID.getId() == null) continue;
Element instanceIDElement = appendNewElement(descriptor, rootElement, CONSTANTS.InstanceID.name());
instanceIDElement.setAttribute(CONSTANTS.val.name(), instanceID.getId().toString());
for (EventedValue eventedValue : instanceID.getValues()) {
generateEventedValue(eventedValue, descriptor, instanceIDElement);
}
}
}
protected void generateEventedValue(EventedValue eventedValue, Document descriptor, Element parentElement) {
String name = eventedValue.getName();
Map.Entry<String, String>[] attributes = eventedValue.getAttributes();
if (attributes != null && attributes.length > 0) {
Element evElement = appendNewElement(descriptor, parentElement, name);
for (Map.Entry<String, String> attr : attributes) {
evElement.setAttribute(attr.getKey(), attr.getValue());
}
}
}
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/LastChangeParser.java | Java | asf20 | 8,346 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @author Christian Bauer
*/
public class Event {
protected List<InstanceID> instanceIDs = new ArrayList();
public Event() {
}
public Event(List<InstanceID> instanceIDs) {
this.instanceIDs = instanceIDs;
}
public List<InstanceID> getInstanceIDs() {
return instanceIDs;
}
public InstanceID getInstanceID(UnsignedIntegerFourBytes id) {
for (InstanceID instanceID : instanceIDs) {
if (instanceID.getId().equals(id)) return instanceID;
}
return null;
}
public void clear() {
instanceIDs = new ArrayList();
}
public void setEventedValue(UnsignedIntegerFourBytes id, EventedValue ev) {
InstanceID instanceID = null;
for (InstanceID i : getInstanceIDs()) {
if (i.getId().equals(id)) {
instanceID = i;
}
}
if (instanceID == null) {
instanceID = new InstanceID(id);
getInstanceIDs().add(instanceID);
}
Iterator<EventedValue> it = instanceID.getValues().iterator();
while (it.hasNext()) {
EventedValue existingEv = it.next();
if (existingEv.getClass().equals(ev.getClass())) {
it.remove();
}
}
instanceID.getValues().add(ev);
}
public <EV extends EventedValue> EV getEventedValue(UnsignedIntegerFourBytes id, Class<EV> type) {
for (InstanceID instanceID : getInstanceIDs()) {
if (instanceID.getId().equals(id)) {
for (EventedValue eventedValue : instanceID.getValues()) {
if (eventedValue.getClass().equals(type))
return (EV) eventedValue;
}
}
}
return null;
}
public boolean hasChanges() {
for (InstanceID instanceID : instanceIDs) {
if (instanceID.getValues().size() > 0) return true;
}
return false;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/Event.java | Java | asf20 | 2,907 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.types.Datatype;
import org.teleal.cling.model.types.InvalidValueException;
import org.teleal.common.util.Exceptions;
import java.net.URI;
import java.util.Map;
import java.util.logging.Logger;
/**
* @author Christian Bauer
*/
public class EventedValueURI extends EventedValue<URI> {
final private static Logger log = Logger.getLogger(EventedValueURI.class.getName());
public EventedValueURI(URI value) {
super(value);
}
public EventedValueURI(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected URI valueOf(String s) throws InvalidValueException {
try {
// These URIs are really defined as 'string' datatype in AVTransport1.0.pdf, but we can try
// to parse whatever devices give us, like the Roku which sends "unknown url".
return super.valueOf(s);
} catch (InvalidValueException ex) {
log.info("Ignoring invalid URI in evented value '" + s +"': " + Exceptions.unwrap(ex));
return null;
}
}
@Override
protected Datatype getDatatype() {
return Datatype.Builtin.URI.getDatatype();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/EventedValueURI.java | Java | asf20 | 1,981 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import java.util.ArrayList;
import java.util.List;
/**
* @author Christian Bauer
*/
public class InstanceID {
protected UnsignedIntegerFourBytes id;
protected List<EventedValue> values = new ArrayList();
public InstanceID(UnsignedIntegerFourBytes id) {
this(id, new ArrayList());
}
public InstanceID(UnsignedIntegerFourBytes id, List<EventedValue> values) {
this.id = id;
this.values = values;
}
public UnsignedIntegerFourBytes getId() {
return id;
}
public List<EventedValue> getValues() {
return values;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/InstanceID.java | Java | asf20 | 1,432 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.lastchange;
import org.teleal.cling.model.types.Datatype;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import java.util.Map;
/**
* @author Christian Bauer
*/
public class EventedValueUnsignedIntegerFourBytes extends EventedValue<UnsignedIntegerFourBytes> {
public EventedValueUnsignedIntegerFourBytes(UnsignedIntegerFourBytes value) {
super(value);
}
public EventedValueUnsignedIntegerFourBytes(Map.Entry<String, String>[] attributes) {
super(attributes);
}
@Override
protected Datatype getDatatype() {
return Datatype.Builtin.UI4.getDatatype();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/lastchange/EventedValueUnsignedIntegerFourBytes.java | Java | asf20 | 1,385 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
*
*/
public class TransportSettings {
private PlayMode playMode = PlayMode.NORMAL;
private RecordQualityMode recQualityMode = RecordQualityMode.NOT_IMPLEMENTED;
public TransportSettings() {
}
public TransportSettings(PlayMode playMode) {
this.playMode = playMode;
}
public TransportSettings(PlayMode playMode, RecordQualityMode recQualityMode) {
this.playMode = playMode;
this.recQualityMode = recQualityMode;
}
public PlayMode getPlayMode() {
return playMode;
}
public RecordQualityMode getRecQualityMode() {
return recQualityMode;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/TransportSettings.java | Java | asf20 | 1,403 |
/*
* Copyright (C) 2011 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
*
* @author Christian Bauer
* @author Mario Franco
*/
public class DIDLAttribute {
private String namespaceURI;
private String prefix;
private String value;
public DIDLAttribute(String namespaceURI, String prefix, String value) {
this.namespaceURI = namespaceURI;
this.prefix = prefix;
this.value = value;
}
/**
* @return the namespaceURI
*/
public String getNamespaceURI() {
return namespaceURI;
}
/**
* @return the prefix
*/
public String getPrefix() {
return prefix;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/DIDLAttribute.java | Java | asf20 | 1,465 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.support.model.container.Album;
import org.teleal.cling.support.model.container.Container;
import org.teleal.cling.support.model.container.GenreContainer;
import org.teleal.cling.support.model.container.MovieGenre;
import org.teleal.cling.support.model.container.MusicAlbum;
import org.teleal.cling.support.model.container.MusicArtist;
import org.teleal.cling.support.model.container.MusicGenre;
import org.teleal.cling.support.model.container.PersonContainer;
import org.teleal.cling.support.model.container.PhotoAlbum;
import org.teleal.cling.support.model.container.PlaylistContainer;
import org.teleal.cling.support.model.container.StorageFolder;
import org.teleal.cling.support.model.container.StorageSystem;
import org.teleal.cling.support.model.container.StorageVolume;
import org.teleal.cling.support.model.item.AudioBook;
import org.teleal.cling.support.model.item.AudioBroadcast;
import org.teleal.cling.support.model.item.AudioItem;
import org.teleal.cling.support.model.item.ImageItem;
import org.teleal.cling.support.model.item.Item;
import org.teleal.cling.support.model.item.Movie;
import org.teleal.cling.support.model.item.MusicTrack;
import org.teleal.cling.support.model.item.MusicVideoClip;
import org.teleal.cling.support.model.item.Photo;
import org.teleal.cling.support.model.item.PlaylistItem;
import org.teleal.cling.support.model.item.TextItem;
import org.teleal.cling.support.model.item.VideoBroadcast;
import org.teleal.cling.support.model.item.VideoItem;
import java.util.ArrayList;
import java.util.List;
/**
* @author Christian Bauer
*/
public class DIDLContent {
public static final String NAMESPACE_URI = "urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/";
public static final String DESC_WRAPPER_NAMESPACE_URI = "urn:teleal-org:cling:support:content-directory-desc-1-0";
protected List<Container> containers = new ArrayList();
protected List<Item> items = new ArrayList();
protected List<DescMeta> descMetadata = new ArrayList();
public Container getFirstContainer() {
return getContainers().get(0);
}
public DIDLContent addContainer(Container container) {
getContainers().add(container);
return this;
}
public List<Container> getContainers() {
return containers;
}
public void setContainers(List<Container> containers) {
this.containers = containers;
}
public DIDLContent addItem(Item item) {
getItems().add(item);
return this;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
public DIDLContent addDescMetadata(DescMeta descMetadata) {
getDescMetadata().add(descMetadata);
return this;
}
public List<DescMeta> getDescMetadata() {
return descMetadata;
}
public void setDescMetadata(List<DescMeta> descMetadata) {
this.descMetadata = descMetadata;
}
public void replaceGenericContainerAndItems() {
setItems(replaceGenericItems(getItems()));
setContainers(replaceGenericContainers(getContainers()));
}
protected List<Item> replaceGenericItems(List<Item> genericItems) {
List<Item> specificItems = new ArrayList();
for (Item genericItem : genericItems) {
String genericType = genericItem.getClazz().getValue();
if (AudioItem.CLASS.getValue().equals(genericType)) {
specificItems.add(new AudioItem(genericItem));
} else if (MusicTrack.CLASS.getValue().equals(genericType)) {
specificItems.add(new MusicTrack(genericItem));
} else if (AudioBook.CLASS.getValue().equals(genericType)) {
specificItems.add(new AudioBook(genericItem));
} else if (AudioBroadcast.CLASS.getValue().equals(genericType)) {
specificItems.add(new AudioBroadcast(genericItem));
} else if (VideoItem.CLASS.getValue().equals(genericType)) {
specificItems.add(new VideoItem(genericItem));
} else if (Movie.CLASS.getValue().equals(genericType)) {
specificItems.add(new Movie(genericItem));
} else if (VideoBroadcast.CLASS.getValue().equals(genericType)) {
specificItems.add(new VideoBroadcast(genericItem));
} else if (MusicVideoClip.CLASS.getValue().equals(genericType)) {
specificItems.add(new MusicVideoClip(genericItem));
} else if (ImageItem.CLASS.getValue().equals(genericType)) {
specificItems.add(new ImageItem(genericItem));
} else if (Photo.CLASS.getValue().equals(genericType)) {
specificItems.add(new Photo(genericItem));
} else if (PlaylistItem.CLASS.getValue().equals(genericType)) {
specificItems.add(new PlaylistItem(genericItem));
} else if (TextItem.CLASS.getValue().equals(genericType)) {
specificItems.add(new TextItem(genericItem));
} else {
specificItems.add(genericItem);
}
}
return specificItems;
}
protected List<Container> replaceGenericContainers(List<Container> genericContainers) {
List<Container> specificContainers = new ArrayList();
for (Container genericContainer : genericContainers) {
String genericType = genericContainer.getClazz().getValue();
Container specific;
if (Album.CLASS.getValue().equals(genericType)) {
specific = new Album(genericContainer);
} else if (MusicAlbum.CLASS.getValue().equals(genericType)) {
specific = new MusicAlbum(genericContainer);
} else if (PhotoAlbum.CLASS.getValue().equals(genericType)) {
specific = new PhotoAlbum(genericContainer);
} else if (GenreContainer.CLASS.getValue().equals(genericType)) {
specific = new GenreContainer(genericContainer);
} else if (MusicGenre.CLASS.getValue().equals(genericType)) {
specific = new MusicGenre(genericContainer);
} else if (MovieGenre.CLASS.getValue().equals(genericType)) {
specific = new MovieGenre(genericContainer);
} else if (PlaylistContainer.CLASS.getValue().equals(genericType)) {
specific = new PlaylistContainer(genericContainer);
} else if (PersonContainer.CLASS.getValue().equals(genericType)) {
specific = new PersonContainer(genericContainer);
} else if (MusicArtist.CLASS.getValue().equals(genericType)) {
specific = new MusicArtist(genericContainer);
} else if (StorageSystem.CLASS.getValue().equals(genericType)) {
specific = new StorageSystem(genericContainer);
} else if (StorageVolume.CLASS.getValue().equals(genericType)) {
specific = new StorageVolume(genericContainer);
} else if (StorageFolder.CLASS.getValue().equals(genericType)) {
specific = new StorageFolder(genericContainer);
} else {
specific = genericContainer;
}
specific.setItems(replaceGenericItems(genericContainer.getItems()));
specificContainers.add(specific);
}
return specificContainers;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/DIDLContent.java | Java | asf20 | 8,206 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
* @author Christian Bauer
*/
public enum TransportState {
STOPPED,
PLAYING,
TRANSITIONING,
PAUSED_PLAYBACK,
PAUSED_RECORDING,
RECORDING,
NO_MEDIA_PRESENT,
CUSTOM;
String value;
TransportState() {
this.value = name();
}
public String getValue() {
return value;
}
public TransportState setValue(String value) {
this.value = value;
return this;
}
public static TransportState valueOrCustomOf(String s) {
try {
return TransportState.valueOf(s);
} catch (IllegalArgumentException ex) {
return TransportState.CUSTOM.setValue(s);
}
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/TransportState.java | Java | asf20 | 1,455 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.ModelUtil;
import java.util.HashMap;
import java.util.Map;
/**
* @author Christian Bauer
*/
public enum StorageMedium {
UNKNOWN,
DV,
MINI_DV("MINI-DV"),
VHS,
W_VHS("W-VHS"),
S_VHS("S-VHS"),
D_VHS("D-VHS"),
VHSC,
VIDEO8,
HI8,
CD_ROM("CD-ROM"),
CD_DA("CD-DA"),
CD_R("CD-R"),
CD_RW("CD-RW"),
VIDEO_CD("VIDEO-CD"),
SACD,
MD_AUDIO("M-AUDIO"),
MD_PICTURE("MD-PICTURE"),
DVD_ROM("DVD-ROM"),
DVD_VIDEO("DVD-VIDEO"),
DVD_R("DVD-R"),
DVD_PLUS_RW("DVD+RW"),
DVD_MINUS_RW("DVD-RW"),
DVD_RAM("DVD-RAM"),
DVD_AUDIO("DVD-AUDIO"),
DAT,
LD,
HDD,
MICRO_MV("MICRO_MV"),
NETWORK,
NONE,
NOT_IMPLEMENTED,
VENDOR_SPECIFIC;
private static Map<String, StorageMedium> byProtocolString = new HashMap<String, StorageMedium>() {{
for (StorageMedium e : StorageMedium.values()) {
put(e.protocolString, e);
}
}};
private String protocolString;
StorageMedium() {
this(null);
}
StorageMedium(String protocolString) {
this.protocolString = protocolString == null ? this.name() : protocolString;
}
@Override
public String toString() {
return protocolString;
}
public static StorageMedium valueOrExceptionOf(String s) {
StorageMedium sm = byProtocolString.get(s);
if (sm != null) return sm;
throw new IllegalArgumentException("Invalid storage medium string: " + s);
}
public static StorageMedium valueOrVendorSpecificOf(String s) {
StorageMedium sm = byProtocolString.get(s);
return sm != null ? sm : StorageMedium.VENDOR_SPECIFIC;
}
public static StorageMedium[] valueOfCommaSeparatedList(String s) {
String[] strings = ModelUtil.fromCommaSeparatedList(s);
if (strings == null) return new StorageMedium[0];
StorageMedium[] result = new StorageMedium[strings.length];
for (int i = 0; i < strings.length; i++) {
result[i] = valueOrVendorSpecificOf(strings[i]);
}
return result;
}
} | zzh84615-mycode | src/org/teleal/cling/support/model/StorageMedium.java | Java | asf20 | 2,902 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
/**
* @author Christian Bauer
*/
public class MusicGenre extends GenreContainer {
public static final Class CLASS = new Class("object.container.genre.musicGenre");
public MusicGenre() {
setClazz(CLASS);
}
public MusicGenre(Container other) {
super(other);
}
public MusicGenre(String id, Container parent, String title, String creator, Integer childCount) {
this(id, parent.getId(), title, creator, childCount);
}
public MusicGenre(String id, String parentID, String title, String creator, Integer childCount) {
super(id, parentID, title, creator, childCount);
setClazz(CLASS);
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/MusicGenre.java | Java | asf20 | 1,441 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class StorageFolder extends Container {
public static final Class CLASS = new Class("object.container.storageFolder");
public StorageFolder() {
setClazz(CLASS);
}
public StorageFolder(Container other) {
super(other);
}
public StorageFolder(String id, Container parent, String title, String creator, Integer childCount,
Long storageUsed) {
this(id, parent.getId(), title, creator, childCount, storageUsed);
}
public StorageFolder(String id, String parentID, String title, String creator, Integer childCount,
Long storageUsed) {
super(id, parentID, title, creator, CLASS, childCount);
if (storageUsed!= null)
setStorageUsed(storageUsed);
}
public Long getStorageUsed() {
return getFirstPropertyValue(UPNP.STORAGE_USED.class);
}
public StorageFolder setStorageUsed(Long l) {
replaceFirstProperty(new UPNP.STORAGE_USED(l));
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/StorageFolder.java | Java | asf20 | 1,914 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
import org.teleal.cling.support.model.Person;
import org.teleal.cling.support.model.StorageMedium;
import java.net.URI;
import java.util.List;
import static org.teleal.cling.support.model.DIDLObject.Property.DC;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class Album extends Container {
public static final Class CLASS = new Class("object.container.album");
public Album() {
setClazz(CLASS);
}
public Album(Container other) {
super(other);
}
public Album(String id, Container parent, String title, String creator, Integer childCount) {
this(id, parent.getId(), title, creator, childCount);
}
public Album(String id, String parentID, String title, String creator, Integer childCount) {
super(id, parentID, title, creator, CLASS, childCount);
}
public String getDescription() {
return getFirstPropertyValue(DC.DESCRIPTION.class);
}
public Album setDescription(String description) {
replaceFirstProperty(new DC.DESCRIPTION(description));
return this;
}
public String getLongDescription() {
return getFirstPropertyValue(UPNP.LONG_DESCRIPTION.class);
}
public Album setLongDescription(String description) {
replaceFirstProperty(new UPNP.LONG_DESCRIPTION(description));
return this;
}
public StorageMedium getStorageMedium() {
return getFirstPropertyValue(UPNP.STORAGE_MEDIUM.class);
}
public Album setStorageMedium(StorageMedium storageMedium) {
replaceFirstProperty(new UPNP.STORAGE_MEDIUM(storageMedium));
return this;
}
public String getDate() {
return getFirstPropertyValue(DC.DATE.class);
}
public Album setDate(String date) {
replaceFirstProperty(new DC.DATE(date));
return this;
}
public URI getFirstRelation() {
return getFirstPropertyValue(DC.RELATION.class);
}
public URI[] getRelations() {
List<URI> list = getPropertyValues(DC.RELATION.class);
return list.toArray(new URI[list.size()]);
}
public Album setRelations(URI[] relations) {
removeProperties(DC.RELATION.class);
for (URI relation : relations) {
addProperty(new DC.RELATION(relation));
}
return this;
}
public String getFirstRights() {
return getFirstPropertyValue(DC.RIGHTS.class);
}
public String[] getRights() {
List<String> list = getPropertyValues(DC.RIGHTS.class);
return list.toArray(new String[list.size()]);
}
public Album setRights(String[] rights) {
removeProperties(DC.RIGHTS.class);
for (String right : rights) {
addProperty(new DC.RIGHTS(right));
}
return this;
}
public Person getFirstContributor() {
return getFirstPropertyValue(DC.CONTRIBUTOR.class);
}
public Person[] getContributors() {
List<Person> list = getPropertyValues(DC.CONTRIBUTOR.class);
return list.toArray(new Person[list.size()]);
}
public Album setContributors(Person[] contributors) {
removeProperties(DC.CONTRIBUTOR.class);
for (Person p : contributors) {
addProperty(new DC.CONTRIBUTOR(p));
}
return this;
}
public Person getFirstPublisher() {
return getFirstPropertyValue(DC.PUBLISHER.class);
}
public Person[] getPublishers() {
List<Person> list = getPropertyValues(DC.PUBLISHER.class);
return list.toArray(new Person[list.size()]);
}
public Album setPublishers(Person[] publishers) {
removeProperties(DC.PUBLISHER.class);
for (Person publisher : publishers) {
addProperty(new DC.PUBLISHER(publisher));
}
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/Album.java | Java | asf20 | 4,646 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
import org.teleal.cling.support.model.DIDLObject;
import org.teleal.cling.support.model.DescMeta;
import org.teleal.cling.support.model.Res;
import org.teleal.cling.support.model.WriteStatus;
import org.teleal.cling.support.model.item.Item;
import java.util.ArrayList;
import java.util.List;
/**
* A container in DIDL content.
* <p>
* Note that although this container can have sub-containers, the
* {@link org.teleal.cling.support.contentdirectory.DIDLParser}
* will never read nor write this collection to and from XML.
* Its only purpose is convenience when creating and manipulating a
* recursive structure, that is, modelling the content tree as you
* see fit. You can then pick a list of containers and/or a list of
* items and hand them to the DIDL parser, which will render them
* flat in XML. The only nested structure that can optionally be
* rendered into and read from XML are the items of containers,
* never their sub-containers.
* </p>
* <p>
* Also see ContentDirectory 1.0 specification, section 2.8.3:
* "Incremental navigation i.e. the full hierarchy is never returned
* in one call since this is likely to flood the resources available to
* the control point (memory, network bandwidth, etc.)."
* </p>
*
* @author Christian Bauer
*/
public class Container extends DIDLObject {
protected Integer childCount = null;
protected boolean searchable; // Default or absent == false
protected List<Class> createClasses = new ArrayList();
protected List<Class> searchClasses = new ArrayList();
protected List<Container> containers = new ArrayList();
protected List<Item> items = new ArrayList();
public Container() {
}
public Container(Container other) {
super(other);
setChildCount(other.getChildCount());
setSearchable(other.isSearchable());
setCreateClasses(other.getCreateClasses());
setSearchClasses(other.getSearchClasses());
setItems(other.getItems());
}
public Container(String id, String parentID, String title, String creator, boolean restricted, WriteStatus writeStatus, Class clazz, List<Res> resources, List<Property> properties, List<DescMeta> descMetadata) {
super(id, parentID, title, creator, restricted, writeStatus, clazz, resources, properties, descMetadata);
}
public Container(String id, String parentID, String title, String creator, boolean restricted, WriteStatus writeStatus, Class clazz, List<Res> resources, List<Property> properties, List<DescMeta> descMetadata, Integer childCount, boolean searchable, List<Class> createClasses, List<Class> searchClasses, List<Item> items) {
super(id, parentID, title, creator, restricted, writeStatus, clazz, resources, properties, descMetadata);
this.childCount = childCount;
this.searchable = searchable;
this.createClasses = createClasses;
this.searchClasses = searchClasses;
this.items = items;
}
public Container(String id, Container parent, String title, String creator, DIDLObject.Class clazz, Integer childCount) {
this(id, parent.getId(), title, creator, true, null, clazz, new ArrayList(), new ArrayList(), new ArrayList(), childCount, false, new ArrayList(), new ArrayList(), new ArrayList());
}
public Container(String id, String parentID, String title, String creator, DIDLObject.Class clazz, Integer childCount) {
this(id, parentID, title, creator, true, null, clazz, new ArrayList(), new ArrayList(), new ArrayList(), childCount, false, new ArrayList(), new ArrayList(), new ArrayList());
}
public Container(String id, Container parent, String title, String creator, DIDLObject.Class clazz, Integer childCount, boolean searchable, List<Class> createClasses, List<Class> searchClasses, List<Item> items) {
this(id, parent.getId(), title, creator, true, null, clazz, new ArrayList(), new ArrayList(), new ArrayList(), childCount, searchable, createClasses, searchClasses, items);
}
public Container(String id, String parentID, String title, String creator, DIDLObject.Class clazz, Integer childCount, boolean searchable, List<Class> createClasses, List<Class> searchClasses, List<Item> items) {
this(id, parentID, title, creator, true, null, clazz, new ArrayList(), new ArrayList(), new ArrayList(), childCount, searchable, createClasses, searchClasses, items);
}
public Integer getChildCount() {
return childCount;
}
public void setChildCount(Integer childCount) {
this.childCount = childCount;
}
public boolean isSearchable() {
return searchable;
}
public void setSearchable(boolean searchable) {
this.searchable = searchable;
}
public List<Class> getCreateClasses() {
return createClasses;
}
public void setCreateClasses(List<Class> createClasses) {
this.createClasses = createClasses;
}
public List<Class> getSearchClasses() {
return searchClasses;
}
public void setSearchClasses(List<Class> searchClasses) {
this.searchClasses = searchClasses;
}
public Container getFirstContainer() {
return getContainers().get(0);
}
public Container addContainer(Container container) {
getContainers().add(container);
return this;
}
public List<Container> getContainers() {
return containers;
}
public void setContainers(List<Container> containers) {
this.containers = containers;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
public Container addItem(Item item) {
getItems().add(item);
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/Container.java | Java | asf20 | 6,556 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
/**
* @author Christian Bauer
*/
public class MovieGenre extends GenreContainer {
public static final Class CLASS = new Class("object.container.genre.movieGenre");
public MovieGenre() {
setClazz(CLASS);
}
public MovieGenre(Container other) {
super(other);
}
public MovieGenre(String id, Container parent, String title, String creator, Integer childCount) {
this(id, parent.getId(), title, creator, childCount);
}
public MovieGenre(String id, String parentID, String title, String creator, Integer childCount) {
super(id, parentID, title, creator, childCount);
setClazz(CLASS);
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/MovieGenre.java | Java | asf20 | 1,441 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
import org.teleal.cling.support.model.item.Item;
import org.teleal.cling.support.model.item.Photo;
import java.util.ArrayList;
import java.util.List;
/**
* @author Christian Bauer
*/
public class PhotoAlbum extends Album {
public static final Class CLASS = new Class("object.container.album.photoAlbum");
public PhotoAlbum() {
setClazz(CLASS);
}
public PhotoAlbum(Container other) {
super(other);
}
public PhotoAlbum(String id, Container parent, String title, String creator, Integer childCount) {
this(id, parent.getId(), title, creator, childCount, null);
}
public PhotoAlbum(String id, Container parent, String title, String creator, Integer childCount, List<Photo> photos) {
this(id, parent.getId(), title, creator, childCount, photos);
}
public PhotoAlbum(String id, String parentID, String title, String creator, Integer childCount) {
this(id, parentID, title, creator, childCount, null);
}
public PhotoAlbum(String id, String parentID, String title, String creator, Integer childCount, List<Photo> photos) {
super(id, parentID, title, creator, childCount);
setClazz(CLASS);
addPhotos(photos);
}
public Photo[] getPhotos() {
List<Photo> list = new ArrayList();
for (Item item : getItems()) {
if (item instanceof Photo) list.add((Photo)item);
}
return list.toArray(new Photo[list.size()]);
}
public void addPhotos(List<Photo> photos) {
addPhotos(photos.toArray(new Photo[photos.size()]));
}
public void addPhotos(Photo[] photos) {
if (photos != null) {
for (Photo photo : photos) {
photo.setAlbum(getTitle());
addItem(photo);
}
}
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/PhotoAlbum.java | Java | asf20 | 2,594 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
import org.teleal.cling.support.model.StorageMedium;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class StorageSystem extends Container {
public static final Class CLASS = new Class("object.container.storageSystem");
public StorageSystem() {
setClazz(CLASS);
}
public StorageSystem(Container other) {
super(other);
}
public StorageSystem(String id, Container parent, String title, String creator, Integer childCount,
Long storageTotal, Long storageUsed, Long storageFree, Long storageMaxPartition, StorageMedium storageMedium) {
this(id, parent.getId(), title, creator, childCount, storageTotal, storageUsed, storageFree, storageMaxPartition, storageMedium);
}
public StorageSystem(String id, String parentID, String title, String creator, Integer childCount,
Long storageTotal, Long storageUsed, Long storageFree, Long storageMaxPartition, StorageMedium storageMedium) {
super(id, parentID, title, creator, CLASS, childCount);
if (storageTotal != null)
setStorageTotal(storageTotal);
if (storageUsed!= null)
setStorageUsed(storageUsed);
if (storageFree != null)
setStorageFree(storageFree);
if (storageMaxPartition != null)
setStorageMaxPartition(storageMaxPartition);
if (storageMedium != null)
setStorageMedium(storageMedium);
}
public Long getStorageTotal() {
return getFirstPropertyValue(UPNP.STORAGE_TOTAL.class);
}
public StorageSystem setStorageTotal(Long l) {
replaceFirstProperty(new UPNP.STORAGE_TOTAL(l));
return this;
}
public Long getStorageUsed() {
return getFirstPropertyValue(UPNP.STORAGE_USED.class);
}
public StorageSystem setStorageUsed(Long l) {
replaceFirstProperty(new UPNP.STORAGE_USED(l));
return this;
}
public Long getStorageFree() {
return getFirstPropertyValue(UPNP.STORAGE_FREE.class);
}
public StorageSystem setStorageFree(Long l) {
replaceFirstProperty(new UPNP.STORAGE_FREE(l));
return this;
}
public Long getStorageMaxPartition() {
return getFirstPropertyValue(UPNP.STORAGE_MAX_PARTITION.class);
}
public StorageSystem setStorageMaxPartition(Long l) {
replaceFirstProperty(new UPNP.STORAGE_MAX_PARTITION(l));
return this;
}
public StorageMedium getStorageMedium() {
return getFirstPropertyValue(UPNP.STORAGE_MEDIUM.class);
}
public StorageSystem setStorageMedium(StorageMedium storageMedium) {
replaceFirstProperty(new UPNP.STORAGE_MEDIUM(storageMedium));
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/StorageSystem.java | Java | asf20 | 3,587 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
import java.net.URI;
import java.util.List;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class MusicArtist extends PersonContainer {
public static final Class CLASS = new Class("object.container.person.musicArtist");
public MusicArtist() {
setClazz(CLASS);
}
public MusicArtist(Container other) {
super(other);
}
public MusicArtist(String id, Container parent, String title, String creator, Integer childCount) {
this(id, parent.getId(), title, creator, childCount);
}
public MusicArtist(String id, String parentID, String title, String creator, Integer childCount) {
super(id, parentID, title, creator, childCount);
setClazz(CLASS);
}
public String getFirstGenre() {
return getFirstPropertyValue(UPNP.GENRE.class);
}
public String[] getGenres() {
List<String> list = getPropertyValues(UPNP.GENRE.class);
return list.toArray(new String[list.size()]);
}
public MusicArtist setGenres(String[] genres) {
removeProperties(UPNP.GENRE.class);
for (String genre : genres) {
addProperty(new UPNP.GENRE(genre));
}
return this;
}
public URI getArtistDiscographyURI() {
return getFirstPropertyValue(UPNP.ARTIST_DISCO_URI.class);
}
public MusicArtist setArtistDiscographyURI(URI uri) {
replaceFirstProperty(new UPNP.ARTIST_DISCO_URI(uri));
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/MusicArtist.java | Java | asf20 | 2,310 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
/**
* @author Christian Bauer
*/
public class GenreContainer extends Container {
public static final Class CLASS = new Class("object.container.genre");
public GenreContainer() {
setClazz(CLASS);
}
public GenreContainer(Container other) {
super(other);
}
public GenreContainer(String id, Container parent, String title, String creator, Integer childCount) {
this(id, parent.getId(), title, creator, childCount);
}
public GenreContainer(String id, String parentID, String title, String creator, Integer childCount) {
super(id, parentID, title, creator, CLASS, childCount);
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/GenreContainer.java | Java | asf20 | 1,427 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
import static org.teleal.cling.support.model.DIDLObject.Property.DC;
/**
* @author Christian Bauer
*/
public class PersonContainer extends Container {
public static final Class CLASS = new Class("object.container.person");
public PersonContainer() {
setClazz(CLASS);
}
public PersonContainer(Container other) {
super(other);
}
public PersonContainer(String id, Container parent, String title, String creator, Integer childCount) {
this(id, parent.getId(), title, creator, childCount);
}
public PersonContainer(String id, String parentID, String title, String creator, Integer childCount) {
super(id, parentID, title, creator, CLASS, childCount);
}
public String getLanguage() {
return getFirstPropertyValue(DC.LANGUAGE.class);
}
public PersonContainer setLanguage(String language) {
replaceFirstProperty(new DC.LANGUAGE(language));
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/PersonContainer.java | Java | asf20 | 1,744 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
import org.teleal.cling.support.model.Person;
import org.teleal.cling.support.model.PersonWithRole;
import org.teleal.cling.support.model.StorageMedium;
import java.util.List;
import static org.teleal.cling.support.model.DIDLObject.Property.DC;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class PlaylistContainer extends Container {
public static final Class CLASS = new Class("object.container.playlist");
public PlaylistContainer() {
setClazz(CLASS);
}
public PlaylistContainer(Container other) {
super(other);
}
public PlaylistContainer(String id, Container parent, String title, String creator, Integer childCount) {
this(id, parent.getId(), title, creator, childCount);
}
public PlaylistContainer(String id, String parentID, String title, String creator, Integer childCount) {
super(id, parentID, title, creator, CLASS, childCount);
}
public PersonWithRole getFirstArtist() {
return getFirstPropertyValue(UPNP.ARTIST.class);
}
public PersonWithRole[] getArtists() {
List<PersonWithRole> list = getPropertyValues(UPNP.ARTIST.class);
return list.toArray(new PersonWithRole[list.size()]);
}
public PlaylistContainer setArtists(PersonWithRole[] artists) {
removeProperties(UPNP.ARTIST.class);
for (PersonWithRole artist : artists) {
addProperty(new UPNP.ARTIST(artist));
}
return this;
}
public String getFirstGenre() {
return getFirstPropertyValue(UPNP.GENRE.class);
}
public String[] getGenres() {
List<String> list = getPropertyValues(UPNP.GENRE.class);
return list.toArray(new String[list.size()]);
}
public PlaylistContainer setGenres(String[] genres) {
removeProperties(UPNP.GENRE.class);
for (String genre : genres) {
addProperty(new UPNP.GENRE(genre));
}
return this;
}
public String getDescription() {
return getFirstPropertyValue(DC.DESCRIPTION.class);
}
public PlaylistContainer setDescription(String description) {
replaceFirstProperty(new DC.DESCRIPTION(description));
return this;
}
public String getLongDescription() {
return getFirstPropertyValue(UPNP.LONG_DESCRIPTION.class);
}
public PlaylistContainer setLongDescription(String description) {
replaceFirstProperty(new UPNP.LONG_DESCRIPTION(description));
return this;
}
public Person getFirstProducer() {
return getFirstPropertyValue(UPNP.PRODUCER.class);
}
public Person[] getProducers() {
List<Person> list = getPropertyValues(UPNP.PRODUCER.class);
return list.toArray(new Person[list.size()]);
}
public PlaylistContainer setProducers(Person[] persons) {
removeProperties(UPNP.PRODUCER.class);
for (Person p : persons) {
addProperty(new UPNP.PRODUCER(p));
}
return this;
}
public StorageMedium getStorageMedium() {
return getFirstPropertyValue(UPNP.STORAGE_MEDIUM.class);
}
public PlaylistContainer setStorageMedium(StorageMedium storageMedium) {
replaceFirstProperty(new UPNP.STORAGE_MEDIUM(storageMedium));
return this;
}
public String getDate() {
return getFirstPropertyValue(DC.DATE.class);
}
public PlaylistContainer setDate(String date) {
replaceFirstProperty(new DC.DATE(date));
return this;
}
public String getFirstRights() {
return getFirstPropertyValue(DC.RIGHTS.class);
}
public String[] getRights() {
List<String> list = getPropertyValues(DC.RIGHTS.class);
return list.toArray(new String[list.size()]);
}
public PlaylistContainer setRights(String[] rights) {
removeProperties(DC.RIGHTS.class);
for (String right : rights) {
addProperty(new DC.RIGHTS(right));
}
return this;
}
public Person getFirstContributor() {
return getFirstPropertyValue(DC.CONTRIBUTOR.class);
}
public Person[] getContributors() {
List<Person> list = getPropertyValues(DC.CONTRIBUTOR.class);
return list.toArray(new Person[list.size()]);
}
public PlaylistContainer setContributors(Person[] contributors) {
removeProperties(DC.CONTRIBUTOR.class);
for (Person p : contributors) {
addProperty(new DC.CONTRIBUTOR(p));
}
return this;
}
public String getLanguage() {
return getFirstPropertyValue(DC.LANGUAGE.class);
}
public PlaylistContainer setLanguage(String language) {
replaceFirstProperty(new DC.LANGUAGE(language));
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/PlaylistContainer.java | Java | asf20 | 5,597 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
import org.teleal.cling.support.model.Person;
import org.teleal.cling.support.model.PersonWithRole;
import org.teleal.cling.support.model.item.Item;
import org.teleal.cling.support.model.item.MusicTrack;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class MusicAlbum extends Album {
public static final Class CLASS = new Class("object.container.album.musicAlbum");
public MusicAlbum() {
setClazz(CLASS);
}
public MusicAlbum(Container other) {
super(other);
}
public MusicAlbum(String id, Container parent, String title, String creator, Integer childCount) {
this(id, parent.getId(), title, creator, childCount, null);
}
public MusicAlbum(String id, Container parent, String title, String creator, Integer childCount, List<MusicTrack> musicTracks) {
this(id, parent.getId(), title, creator, childCount, musicTracks);
}
public MusicAlbum(String id, String parentID, String title, String creator, Integer childCount) {
this(id, parentID, title, creator, childCount, null);
}
public MusicAlbum(String id, String parentID, String title, String creator, Integer childCount, List<MusicTrack> musicTracks) {
super(id, parentID, title, creator, childCount);
setClazz(CLASS);
addMusicTracks(musicTracks);
}
public PersonWithRole getFirstArtist() {
return getFirstPropertyValue(UPNP.ARTIST.class);
}
public PersonWithRole[] getArtists() {
List<PersonWithRole> list = getPropertyValues(UPNP.ARTIST.class);
return list.toArray(new PersonWithRole[list.size()]);
}
public MusicAlbum setArtists(PersonWithRole[] artists) {
removeProperties(UPNP.ARTIST.class);
for (PersonWithRole artist : artists) {
addProperty(new UPNP.ARTIST(artist));
}
return this;
}
public String getFirstGenre() {
return getFirstPropertyValue(UPNP.GENRE.class);
}
public String[] getGenres() {
List<String> list = getPropertyValues(UPNP.GENRE.class);
return list.toArray(new String[list.size()]);
}
public MusicAlbum setGenres(String[] genres) {
removeProperties(UPNP.GENRE.class);
for (String genre : genres) {
addProperty(new UPNP.GENRE(genre));
}
return this;
}
public Person getFirstProducer() {
return getFirstPropertyValue(UPNP.PRODUCER.class);
}
public Person[] getProducers() {
List<Person> list = getPropertyValues(UPNP.PRODUCER.class);
return list.toArray(new Person[list.size()]);
}
public MusicAlbum setProducers(Person[] persons) {
removeProperties(UPNP.PRODUCER.class);
for (Person p : persons) {
addProperty(new UPNP.PRODUCER(p));
}
return this;
}
public URI getFirstAlbumArtURI() {
return getFirstPropertyValue(UPNP.ALBUM_ART_URI.class);
}
public URI[] getAlbumArtURIs() {
List<URI> list = getPropertyValues(UPNP.ALBUM_ART_URI.class);
return list.toArray(new URI[list.size()]);
}
public MusicAlbum setAlbumArtURIs(URI[] uris) {
removeProperties(UPNP.ALBUM_ART_URI.class);
for (URI uri : uris) {
addProperty(new UPNP.ALBUM_ART_URI(uri));
}
return this;
}
public String getToc() {
return getFirstPropertyValue(UPNP.TOC.class);
}
public MusicAlbum setToc(String toc) {
replaceFirstProperty(new UPNP.TOC(toc));
return this;
}
public MusicTrack[] getMusicTracks() {
List<MusicTrack> list = new ArrayList();
for (Item item : getItems()) {
if (item instanceof MusicTrack) list.add((MusicTrack)item);
}
return list.toArray(new MusicTrack[list.size()]);
}
public void addMusicTracks(List<MusicTrack> musicTracks) {
addMusicTracks(musicTracks.toArray(new MusicTrack[musicTracks.size()]));
}
public void addMusicTracks(MusicTrack[] musicTracks) {
if (musicTracks != null) {
for (MusicTrack musicTrack : musicTracks) {
musicTrack.setAlbum(getTitle());
addItem(musicTrack);
}
}
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/MusicAlbum.java | Java | asf20 | 5,157 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.container;
import org.teleal.cling.support.model.StorageMedium;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class StorageVolume extends Container {
public static final Class CLASS = new Class("object.container.storageVolume");
public StorageVolume() {
setClazz(CLASS);
}
public StorageVolume(Container other) {
super(other);
}
public StorageVolume(String id, Container parent, String title, String creator, Integer childCount,
Long storageTotal, Long storageUsed, Long storageFree, StorageMedium storageMedium) {
this(id, parent.getId(), title, creator, childCount, storageTotal, storageUsed, storageFree, storageMedium);
}
public StorageVolume(String id, String parentID, String title, String creator, Integer childCount,
Long storageTotal, Long storageUsed, Long storageFree, StorageMedium storageMedium) {
super(id, parentID, title, creator, CLASS, childCount);
if (storageTotal != null)
setStorageTotal(storageTotal);
if (storageUsed!= null)
setStorageUsed(storageUsed);
if (storageFree != null)
setStorageFree(storageFree);
if (storageMedium != null)
setStorageMedium(storageMedium);
}
public Long getStorageTotal() {
return getFirstPropertyValue(UPNP.STORAGE_TOTAL.class);
}
public StorageVolume setStorageTotal(Long l) {
replaceFirstProperty(new UPNP.STORAGE_TOTAL(l));
return this;
}
public Long getStorageUsed() {
return getFirstPropertyValue(UPNP.STORAGE_USED.class);
}
public StorageVolume setStorageUsed(Long l) {
replaceFirstProperty(new UPNP.STORAGE_USED(l));
return this;
}
public Long getStorageFree() {
return getFirstPropertyValue(UPNP.STORAGE_FREE.class);
}
public StorageVolume setStorageFree(Long l) {
replaceFirstProperty(new UPNP.STORAGE_FREE(l));
return this;
}
public StorageMedium getStorageMedium() {
return getFirstPropertyValue(UPNP.STORAGE_MEDIUM.class);
}
public StorageVolume setStorageMedium(StorageMedium storageMedium) {
replaceFirstProperty(new UPNP.STORAGE_MEDIUM(storageMedium));
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/container/StorageVolume.java | Java | asf20 | 3,151 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.types.InvalidValueException;
import org.teleal.common.util.MimeType;
/**
* Encaspulates a MIME type (content format) and transport, protocol, additional information.
*
* @author Christian Bauer
*/
public class ProtocolInfo {
public static final String WILDCARD = "*";
public static final String TRAILING_ZEROS = "000000000000000000000000";
public static final class DLNAFlags {
public static final int SENDER_PACED = (1 << 31);
public static final int TIME_BASED_SEEK = (1 << 30);
public static final int BYTE_BASED_SEEK = (1 << 29);
public static final int FLAG_PLAY_CONTAINER = (1 << 28);
public static final int S0_INCREASE = (1 << 27);
public static final int SN_INCREASE = (1 << 26);
public static final int RTSP_PAUSE = (1 << 25);
public static final int STREAMING_TRANSFER_MODE = (1 << 24);
public static final int INTERACTIVE_TRANSFERT_MODE = (1 << 23);
public static final int BACKGROUND_TRANSFERT_MODE = (1 << 22);
public static final int CONNECTION_STALL = (1 << 21);
public static final int DLNA_V15 = (1 << 20);
}
protected Protocol protocol = Protocol.ALL;
protected String network = WILDCARD;
protected String contentFormat = WILDCARD;
protected String additionalInfo = WILDCARD;
public ProtocolInfo(String s) throws InvalidValueException {
if (s == null) throw new NullPointerException();
s = s.trim();
String[] split = s.split(":");
if (split.length != 4) {
throw new InvalidValueException("Can't parse ProtocolInfo string: " + s);
}
this.protocol = Protocol.valueOrNullOf(split[0]);
this.network = split[1];
this.contentFormat = split[2];
this.additionalInfo = split[3];
}
public ProtocolInfo(MimeType contentFormatMimeType) {
this.protocol = Protocol.HTTP_GET;
this.contentFormat = contentFormatMimeType.toString();
}
public ProtocolInfo(Protocol protocol, String network, String contentFormat, String additionalInfo) {
this.protocol = protocol;
this.network = network;
this.contentFormat = contentFormat;
this.additionalInfo = additionalInfo;
}
public Protocol getProtocol() {
return protocol;
}
public String getNetwork() {
return network;
}
public String getContentFormat() {
return contentFormat;
}
public MimeType getContentFormatMimeType() throws IllegalArgumentException {
return MimeType.valueOf(contentFormat);
}
public String getAdditionalInfo() {
return additionalInfo;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ProtocolInfo that = (ProtocolInfo) o;
if (!additionalInfo.equals(that.additionalInfo)) return false;
if (!contentFormat.equals(that.contentFormat)) return false;
if (!network.equals(that.network)) return false;
if (protocol != that.protocol) return false;
return true;
}
@Override
public int hashCode() {
int result = protocol.hashCode();
result = 31 * result + network.hashCode();
result = 31 * result + contentFormat.hashCode();
result = 31 * result + additionalInfo.hashCode();
return result;
}
@Override
public String toString() {
return protocol.toString() + ":" +
network + ":" +
contentFormat + ":" +
additionalInfo;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/ProtocolInfo.java | Java | asf20 | 4,440 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.ModelUtil;
import org.teleal.cling.model.types.InvalidValueException;
import java.util.ArrayList;
/**
* @author Christian Bauer
*/
public class ProtocolInfos extends ArrayList<ProtocolInfo> {
public ProtocolInfos(ProtocolInfo... info) {
for (ProtocolInfo protocolInfo : info) {
add(protocolInfo);
}
}
public ProtocolInfos(String s) throws InvalidValueException {
String[] infos = ModelUtil.fromCommaSeparatedList(s);
if (infos != null)
for (String info : infos)
add(new ProtocolInfo(info));
}
@Override
public String toString() {
return ModelUtil.toCommaSeparatedList(toArray(new ProtocolInfo[size()]));
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/ProtocolInfos.java | Java | asf20 | 1,519 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
*
*/
public enum Channel {
Master,
LF,
RF,
CF,
LFE,
LS,
RS,
LFC,
RFC,
SD,
SL,
SR,
T
}
| zzh84615-mycode | src/org/teleal/cling/support/model/Channel.java | Java | asf20 | 910 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
*
*/
public enum Protocol {
ALL(ProtocolInfo.WILDCARD),
HTTP_GET("http-get"),
RTSP_RTP_UDP("rtsp-rtp-udp"),
INTERNAL("internal"),
IEC61883("iec61883");
private String protocolString;
Protocol(String protocolString) {
this.protocolString = protocolString;
}
@Override
public String toString() {
return protocolString;
}
public static Protocol valueOrNullOf(String s) {
for (Protocol protocol : values()) {
if (protocol.toString().equals(s)) {
return protocol;
}
}
return null;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/Protocol.java | Java | asf20 | 1,390 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.model.action.ActionArgumentValue;
import java.util.Map;
/**
*
*/
public class MediaInfo {
private String currentURI = "";
private String currentURIMetaData = "";
private String nextURI = "NOT_IMPLEMENTED";
private String nextURIMetaData = "NOT_IMPLEMENTED";
private UnsignedIntegerFourBytes numberOfTracks = new UnsignedIntegerFourBytes(0);
private String mediaDuration = "00:00:00";
private StorageMedium playMedium = StorageMedium.NONE;
private StorageMedium recordMedium = StorageMedium.NOT_IMPLEMENTED;
private RecordMediumWriteStatus writeStatus = RecordMediumWriteStatus.NOT_IMPLEMENTED;
public MediaInfo() {
}
public MediaInfo(Map<String, ActionArgumentValue> args) {
this(
(String) args.get("CurrentURI").getValue(),
(String) args.get("CurrentURIMetaData").getValue(),
(String) args.get("NextURI").getValue(),
(String) args.get("NextURIMetaData").getValue(),
(UnsignedIntegerFourBytes) args.get("NrTracks").getValue(),
(String) args.get("MediaDuration").getValue(),
StorageMedium.valueOrVendorSpecificOf((String) args.get("PlayMedium").getValue()),
StorageMedium.valueOrVendorSpecificOf((String) args.get("RecordMedium").getValue()),
RecordMediumWriteStatus.valueOrUnknownOf((String) args.get("WriteStatus").getValue())
);
}
public MediaInfo(String currentURI, String currentURIMetaData) {
this.currentURI = currentURI;
this.currentURIMetaData = currentURIMetaData;
}
public MediaInfo(String currentURI, String currentURIMetaData,
UnsignedIntegerFourBytes numberOfTracks, String mediaDuration,
StorageMedium playMedium) {
this.currentURI = currentURI;
this.currentURIMetaData = currentURIMetaData;
this.numberOfTracks = numberOfTracks;
this.mediaDuration = mediaDuration;
this.playMedium = playMedium;
}
public MediaInfo(String currentURI, String currentURIMetaData,
UnsignedIntegerFourBytes numberOfTracks, String mediaDuration,
StorageMedium playMedium,
StorageMedium recordMedium, RecordMediumWriteStatus writeStatus) {
this.currentURI = currentURI;
this.currentURIMetaData = currentURIMetaData;
this.numberOfTracks = numberOfTracks;
this.mediaDuration = mediaDuration;
this.playMedium = playMedium;
this.recordMedium = recordMedium;
this.writeStatus = writeStatus;
}
public MediaInfo(String currentURI, String currentURIMetaData,
String nextURI, String nextURIMetaData,
UnsignedIntegerFourBytes numberOfTracks, String mediaDuration,
StorageMedium playMedium) {
this.currentURI = currentURI;
this.currentURIMetaData = currentURIMetaData;
this.nextURI = nextURI;
this.nextURIMetaData = nextURIMetaData;
this.numberOfTracks = numberOfTracks;
this.mediaDuration = mediaDuration;
this.playMedium = playMedium;
}
public MediaInfo(String currentURI, String currentURIMetaData,
String nextURI, String nextURIMetaData,
UnsignedIntegerFourBytes numberOfTracks, String mediaDuration,
StorageMedium playMedium,
StorageMedium recordMedium, RecordMediumWriteStatus writeStatus) {
this.currentURI = currentURI;
this.currentURIMetaData = currentURIMetaData;
this.nextURI = nextURI;
this.nextURIMetaData = nextURIMetaData;
this.numberOfTracks = numberOfTracks;
this.mediaDuration = mediaDuration;
this.playMedium = playMedium;
this.recordMedium = recordMedium;
this.writeStatus = writeStatus;
}
public String getCurrentURI() {
return currentURI;
}
public String getCurrentURIMetaData() {
return currentURIMetaData;
}
public String getNextURI() {
return nextURI;
}
public String getNextURIMetaData() {
return nextURIMetaData;
}
public UnsignedIntegerFourBytes getNumberOfTracks() {
return numberOfTracks;
}
public String getMediaDuration() {
return mediaDuration;
}
public StorageMedium getPlayMedium() {
return playMedium;
}
public StorageMedium getRecordMedium() {
return recordMedium;
}
public RecordMediumWriteStatus getWriteStatus() {
return writeStatus;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/MediaInfo.java | Java | asf20 | 5,522 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.support.lastchange.LastChange;
/**
* State of one logical instance of the AV Transport service.
*
* @author Christian Bauer
*/
public class AVTransport {
final protected UnsignedIntegerFourBytes instanceID;
final protected LastChange lastChange;
protected MediaInfo mediaInfo;
protected TransportInfo transportInfo;
protected PositionInfo positionInfo;
protected DeviceCapabilities deviceCapabilities;
protected TransportSettings transportSettings;
public AVTransport(UnsignedIntegerFourBytes instanceID, LastChange lastChange, StorageMedium possiblePlayMedium) {
this(instanceID, lastChange, new StorageMedium[]{possiblePlayMedium});
}
public AVTransport(UnsignedIntegerFourBytes instanceID, LastChange lastChange, StorageMedium[] possiblePlayMedia) {
this.instanceID = instanceID;
this.lastChange = lastChange;
setDeviceCapabilities(new DeviceCapabilities(possiblePlayMedia));
setMediaInfo(new MediaInfo());
setTransportInfo(new TransportInfo());
setPositionInfo(new PositionInfo());
setTransportSettings(new TransportSettings());
}
public UnsignedIntegerFourBytes getInstanceId() {
return instanceID;
}
public LastChange getLastChange() {
return lastChange;
}
public MediaInfo getMediaInfo() {
return mediaInfo;
}
public void setMediaInfo(MediaInfo mediaInfo) {
this.mediaInfo = mediaInfo;
}
public TransportInfo getTransportInfo() {
return transportInfo;
}
public void setTransportInfo(TransportInfo transportInfo) {
this.transportInfo = transportInfo;
}
public PositionInfo getPositionInfo() {
return positionInfo;
}
public void setPositionInfo(PositionInfo positionInfo) {
this.positionInfo = positionInfo;
}
public DeviceCapabilities getDeviceCapabilities() {
return deviceCapabilities;
}
public void setDeviceCapabilities(DeviceCapabilities deviceCapabilities) {
this.deviceCapabilities = deviceCapabilities;
}
public TransportSettings getTransportSettings() {
return transportSettings;
}
public void setTransportSettings(TransportSettings transportSettings) {
this.transportSettings = transportSettings;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/AVTransport.java | Java | asf20 | 3,190 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
/**
* @author Christian Bauer
*/
public class Connection {
static public class StatusInfo {
private Status status;
private long uptimeSeconds;
private Error lastError;
public StatusInfo(Status status, UnsignedIntegerFourBytes uptime, Error lastError) {
this(status, uptime.getValue(), lastError);
}
public StatusInfo(Status status, long uptimeSeconds, Error lastError) {
this.status = status;
this.uptimeSeconds = uptimeSeconds;
this.lastError = lastError;
}
public Status getStatus() {
return status;
}
public long getUptimeSeconds() {
return uptimeSeconds;
}
public UnsignedIntegerFourBytes getUptime() {
return new UnsignedIntegerFourBytes(getUptimeSeconds());
}
public Error getLastError() {
return lastError;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StatusInfo that = (StatusInfo) o;
if (uptimeSeconds != that.uptimeSeconds) return false;
if (lastError != that.lastError) return false;
if (status != that.status) return false;
return true;
}
@Override
public int hashCode() {
int result = status.hashCode();
result = 31 * result + (int) (uptimeSeconds ^ (uptimeSeconds >>> 32));
result = 31 * result + lastError.hashCode();
return result;
}
@Override
public String toString() {
return "(" + getClass().getSimpleName() + ") " + getStatus();
}
}
public enum Type {
/**
* Valid connection types cannot be identified.
*/
Unconfigured,
/**
* The Internet Gateway is an IP router between the LAN and the WAN connection.
*/
IP_Routed,
/**
* The Internet Gateway is an Ethernet bridge between the LAN and the WAN connection.
*/
IP_Bridged
}
public enum Status {
/**
* This value indicates that other variables in the service table are
* uninitialized or in an invalid state.
*/
Unconfigured,
/**
* The WANConnectionDevice is in the process of initiating a connection
* for the first time after the connection became disconnected.
*/
Connecting,
/**
* At least one client has successfully
* initiated an Internet connection using this instance.
*/
Connected,
/**
* The connection is active (packets are allowed to flow
* through), but will transition to Disconnecting state after a certain period.
*/
PendingDisconnect,
/**
* The WANConnectionDevice is in the process of terminating a connection.
* On successful termination, ConnectionStatus transitions to Disconnected.
*/
Disconnecting,
/**
* No ISP connection is active (or being activated) from this connection
* instance. No packets are transiting the gateway.
*/
Disconnected
}
public enum Error {
ERROR_NONE,
ERROR_COMMAND_ABORTED,
ERROR_NOT_ENABLED_FOR_INTERNET,
ERROR_USER_DISCONNECT,
ERROR_ISP_DISCONNECT,
ERROR_IDLE_DISCONNECT,
ERROR_FORCED_DISCONNECT,
ERROR_NO_CARRIER,
ERROR_IP_CONFIGURATION,
ERROR_UNKNOWN
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/Connection.java | Java | asf20 | 4,522 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.parsers.DocumentBuilderFactory;
import java.net.URI;
/**
* Descriptor metadata about an item/resource.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <any namespace='##other'/>
* </sequence>
* <attribute name="id" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="nameSpace" use="required" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
public class DescMeta<M> {
protected String id;
protected String type;
protected URI nameSpace;
protected M metadata;
public DescMeta() {
}
public DescMeta(String id, String type, URI nameSpace, M metadata) {
this.id = id;
this.type = type;
this.nameSpace = nameSpace;
this.metadata = metadata;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public URI getNameSpace() {
return nameSpace;
}
public void setNameSpace(URI nameSpace) {
this.nameSpace = nameSpace;
}
public M getMetadata() {
return metadata;
}
public void setMetadata(M metadata) {
this.metadata = metadata;
}
public Document createMetadataDocument() {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document d = factory.newDocumentBuilder().newDocument();
Element rootElement = d.createElementNS(DIDLContent.DESC_WRAPPER_NAMESPACE_URI, "desc-wrapper");
d.appendChild(rootElement);
return d;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/DescMeta.java | Java | asf20 | 2,985 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.ModelUtil;
import java.util.ArrayList;
import java.util.List;
/**
* @author Christian Bauer
*/
public enum TransportAction {
Play,
Stop,
Pause,
Seek,
Next,
Previous,
Record;
public static TransportAction[] valueOfCommaSeparatedList(String s) {
String[] strings = ModelUtil.fromCommaSeparatedList(s);
if (strings == null) return new TransportAction[0];
List<TransportAction> result = new ArrayList();
for (String taString : strings) {
for (TransportAction ta : values()) {
if (ta.name().equals(taString)) {
result.add(ta);
}
}
}
return result.toArray(new TransportAction[result.size()]);
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/TransportAction.java | Java | asf20 | 1,554 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.action.ActionArgumentValue;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import org.teleal.cling.model.types.UnsignedIntegerTwoBytes;
import java.util.Map;
/**
* @author Christian Bauer
*/
public class PortMapping {
public enum Protocol {
UDP,
TCP
}
private boolean enabled;
private UnsignedIntegerFourBytes leaseDurationSeconds;
private String remoteHost;
private UnsignedIntegerTwoBytes externalPort;
private UnsignedIntegerTwoBytes internalPort;
private String internalClient;
private Protocol protocol;
private String description;
public PortMapping() {
}
public PortMapping(Map<String, ActionArgumentValue<Service>> map) {
this(
(Boolean) map.get("NewEnabled").getValue(),
(UnsignedIntegerFourBytes) map.get("NewLeaseDuration").getValue(),
(String) map.get("NewRemoteHost").getValue(),
(UnsignedIntegerTwoBytes) map.get("NewExternalPort").getValue(),
(UnsignedIntegerTwoBytes) map.get("NewInternalPort").getValue(),
(String) map.get("NewInternalClient").getValue(),
Protocol.valueOf(map.get("NewProtocol").toString()),
(String) map.get("NewPortMappingDescription").getValue()
);
}
public PortMapping(int port, String internalClient, Protocol protocol) {
this(
true,
new UnsignedIntegerFourBytes(0),
null,
new UnsignedIntegerTwoBytes(port),
new UnsignedIntegerTwoBytes(port),
internalClient,
protocol,
null
);
}
public PortMapping(int port, String internalClient, Protocol protocol, String description) {
this(
true,
new UnsignedIntegerFourBytes(0),
null,
new UnsignedIntegerTwoBytes(port),
new UnsignedIntegerTwoBytes(port),
internalClient,
protocol,
description
);
}
public PortMapping(String remoteHost, UnsignedIntegerTwoBytes externalPort, Protocol protocol) {
this(
true,
new UnsignedIntegerFourBytes(0),
remoteHost,
externalPort,
null,
null,
protocol,
null
);
}
public PortMapping(boolean enabled, UnsignedIntegerFourBytes leaseDurationSeconds, String remoteHost, UnsignedIntegerTwoBytes externalPort,
UnsignedIntegerTwoBytes internalPort, String internalClient, Protocol protocol, String description) {
this.enabled = enabled;
this.leaseDurationSeconds = leaseDurationSeconds;
this.remoteHost = remoteHost;
this.externalPort = externalPort;
this.internalPort = internalPort;
this.internalClient = internalClient;
this.protocol = protocol;
this.description = description;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public UnsignedIntegerFourBytes getLeaseDurationSeconds() {
return leaseDurationSeconds;
}
public void setLeaseDurationSeconds(UnsignedIntegerFourBytes leaseDurationSeconds) {
this.leaseDurationSeconds = leaseDurationSeconds;
}
public boolean hasRemoteHost() {
return remoteHost != null && remoteHost.length() > 0;
}
public String getRemoteHost() {
return remoteHost == null ? "-" : remoteHost;
}
public void setRemoteHost(String remoteHost) {
this.remoteHost = remoteHost == null || remoteHost.equals("-") || remoteHost.length() == 0 ? null : remoteHost;
}
public UnsignedIntegerTwoBytes getExternalPort() {
return externalPort;
}
public void setExternalPort(UnsignedIntegerTwoBytes externalPort) {
this.externalPort = externalPort;
}
public UnsignedIntegerTwoBytes getInternalPort() {
return internalPort;
}
public void setInternalPort(UnsignedIntegerTwoBytes internalPort) {
this.internalPort = internalPort;
}
public String getInternalClient() {
return internalClient;
}
public void setInternalClient(String internalClient) {
this.internalClient = internalClient;
}
public Protocol getProtocol() {
return protocol;
}
public void setProtocol(Protocol protocol) {
this.protocol = protocol;
}
public boolean hasDescription() {
return description != null;
}
public String getDescription() {
return description == null ? "-" : description;
}
public void setDescription(String description) {
this.description = description == null || description.equals("-") || description.length() == 0 ? null : description;
}
@Override
public String toString() {
return "(" + getClass().getSimpleName() + ") Protocol: " + getProtocol() + ", " + getExternalPort() + " => " + getInternalClient();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/PortMapping.java | Java | asf20 | 6,046 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
* @author Alessio Gaeta
* @author Christian Bauer
*/
public enum BrowseFlag {
METADATA("BrowseMetadata"),
DIRECT_CHILDREN("BrowseDirectChildren");
private String protocolString;
BrowseFlag(String protocolString) {
this.protocolString = protocolString;
}
@Override
public String toString() {
return protocolString;
}
public static BrowseFlag valueOrNullOf(String s) {
for (BrowseFlag browseFlag : values()) {
if (browseFlag.toString().equals(s))
return browseFlag;
}
return null;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/BrowseFlag.java | Java | asf20 | 1,293 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.action.ActionArgumentValue;
import java.util.Map;
/**
*
*/
public class TransportInfo {
private TransportState currentTransportState = TransportState.NO_MEDIA_PRESENT;
private TransportStatus currentTransportStatus = TransportStatus.OK;
private String currentSpeed = "1";
public TransportInfo() {
}
public TransportInfo(Map<String, ActionArgumentValue> args) {
this(
TransportState.valueOrCustomOf((String) args.get("CurrentTransportState").getValue()),
TransportStatus.valueOrCustomOf((String) args.get("CurrentTransportStatus").getValue()),
(String) args.get("CurrentSpeed").getValue()
);
}
public TransportInfo(TransportState currentTransportState) {
this.currentTransportState = currentTransportState;
}
public TransportInfo(TransportState currentTransportState, String currentSpeed) {
this.currentTransportState = currentTransportState;
this.currentSpeed = currentSpeed;
}
public TransportInfo(TransportState currentTransportState, TransportStatus currentTransportStatus) {
this.currentTransportState = currentTransportState;
this.currentTransportStatus = currentTransportStatus;
}
public TransportInfo(TransportState currentTransportState, TransportStatus currentTransportStatus, String currentSpeed) {
this.currentTransportState = currentTransportState;
this.currentTransportStatus = currentTransportStatus;
this.currentSpeed = currentSpeed;
}
public TransportState getCurrentTransportState() {
return currentTransportState;
}
public TransportStatus getCurrentTransportStatus() {
return currentTransportStatus;
}
public String getCurrentSpeed() {
return currentSpeed;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/TransportInfo.java | Java | asf20 | 2,625 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
* @author Christian Bauer
*/
public enum WriteStatus {
WRITABLE,
NOT_WRITABLE,
UNKNOWN,
MIXED
}
| zzh84615-mycode | src/org/teleal/cling/support/model/WriteStatus.java | Java | asf20 | 885 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
/**
* @author Alessio Gaeta
* @author Christian Bauer
*/
public class BrowseResult {
protected String result;
protected UnsignedIntegerFourBytes count;
protected UnsignedIntegerFourBytes totalMatches;
protected UnsignedIntegerFourBytes containerUpdateID;
public BrowseResult(String result, UnsignedIntegerFourBytes count,
UnsignedIntegerFourBytes totalMatches,
UnsignedIntegerFourBytes containerUpdateID) {
this.result = result;
this.count = count;
this.totalMatches = totalMatches;
this.containerUpdateID = containerUpdateID;
}
public BrowseResult(String result, long count, long totalMatches) {
this(result, count, totalMatches, 0);
}
public BrowseResult(String result, long count, long totalMatches, long updatedId) {
this(
result,
new UnsignedIntegerFourBytes(count),
new UnsignedIntegerFourBytes(totalMatches),
new UnsignedIntegerFourBytes(updatedId)
);
}
public String getResult() {
return result;
}
public UnsignedIntegerFourBytes getCount() {
return count;
}
public long getCountLong() {
return count.getValue();
}
public UnsignedIntegerFourBytes getTotalMatches() {
return totalMatches;
}
public long getTotalMatchesLong() {
return totalMatches.getValue();
}
public UnsignedIntegerFourBytes getContainerUpdateID() {
return containerUpdateID;
}
public long getContainerUpdateIDLong() {
return containerUpdateID.getValue();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/BrowseResult.java | Java | asf20 | 2,500 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
*
*/
public enum TransportStatus {
OK,
ERROR_OCCURED,
CUSTOM;
String value;
TransportStatus() {
this.value = name();
}
public String getValue() {
return value;
}
public TransportStatus setValue(String value) {
this.value = value;
return this;
}
public static TransportStatus valueOrCustomOf(String s) {
try {
return TransportStatus.valueOf(s);
} catch (IllegalArgumentException ex) {
return TransportStatus.CUSTOM.setValue(s);
}
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/TransportStatus.java | Java | asf20 | 1,339 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.ModelUtil;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
public enum RecordQualityMode {
EP("0:EP"),
LP("1:LP"),
SP("2:SP"),
BASIC("0:BASIC"),
MEDIUM("1:MEDIUM"),
HIGH("2:HIGH"),
NOT_IMPLEMENTED("NOT_IMPLEMENTED");
private String protocolString;
RecordQualityMode(String protocolString) {
this.protocolString = protocolString;
}
@Override
public String toString() {
return protocolString;
}
public static RecordQualityMode valueOrExceptionOf(String s) throws IllegalArgumentException {
for (RecordQualityMode recordQualityMode : values()) {
if (recordQualityMode.protocolString.equals(s)) {
return recordQualityMode;
}
}
throw new IllegalArgumentException("Invalid record quality mode string: " + s);
}
public static RecordQualityMode[] valueOfCommaSeparatedList(String s) {
String[] strings = ModelUtil.fromCommaSeparatedList(s);
if (strings == null) return new RecordQualityMode[0];
List<RecordQualityMode> result = new ArrayList();
for (String rqm : strings) {
for (RecordQualityMode recordQualityMode : values()) {
if (recordQualityMode.protocolString.equals(rqm)) {
result.add(recordQualityMode);
}
}
}
return result.toArray(new RecordQualityMode[result.size()]);
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/RecordQualityMode.java | Java | asf20 | 2,265 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
*
*/
public enum PresetName {
FactoryDefault
}
| zzh84615-mycode | src/org/teleal/cling/support/model/PresetName.java | Java | asf20 | 823 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
* @author Christian Bauer
*/
public class Person {
private String name;
public Person(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Person person = (Person) o;
if (!name.equals(person.name)) return false;
return true;
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public String toString() {
return getName();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/Person.java | Java | asf20 | 1,409 |
/*
* Copyright (C) 2011 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.w3c.dom.Element;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @author Christian Bauer
* @author Mario Franco
*/
public abstract class DIDLObject {
static public abstract class Property<V> {
public interface NAMESPACE {
}
private V value;
final private String descriptorName;
final private List<Property<DIDLAttribute>> attributes = new ArrayList<Property<DIDLAttribute>>();
protected Property() {
this(null, null);
}
protected Property(String descriptorName) {
this(null, descriptorName);
}
protected Property(V value, String descriptorName) {
this.value = value;
this.descriptorName = descriptorName == null ? getClass().getSimpleName().toLowerCase() : descriptorName;
}
protected Property(V value, String descriptorName, List<Property<DIDLAttribute>> attributes) {
this.value = value;
this.descriptorName = descriptorName == null ? getClass().getSimpleName().toLowerCase() : descriptorName;
this.attributes.addAll(attributes);
}
public V getValue() {
return value;
}
public void setValue(V value) {
this.value = value;
}
public String getDescriptorName() {
return descriptorName;
}
public void setOnElement(Element element) {
element.setTextContent(toString());
for (Property<DIDLAttribute> attr : attributes) {
element.setAttributeNS(
attr.getValue().getNamespaceURI(),
attr.getValue().getPrefix() + ':' + attr.getDescriptorName(),
attr.getValue().getValue());
}
}
public void addAttribute(Property<DIDLAttribute> attr) {
this.attributes.add(attr);
}
public void removeAttribute(Property<DIDLAttribute> attr) {
this.attributes.remove(attr);
}
public void removeAttribute(String descriptorName) {
for (Property<DIDLAttribute> attr : attributes) {
if (attr.getDescriptorName().equals(descriptorName)) {
this.removeAttribute(attr);
break;
}
}
}
public Property<DIDLAttribute> getAttribute(String descriptorName) {
for (Property<DIDLAttribute> attr : attributes) {
if (attr.getDescriptorName().equals(descriptorName)) {
return attr;
}
}
return null;
}
@Override
public String toString() {
return getValue() != null ? getValue().toString() : "";
}
static public class PropertyPersonWithRole extends Property<PersonWithRole> {
public PropertyPersonWithRole() {
}
public PropertyPersonWithRole(String descriptorName) {
super(descriptorName);
}
public PropertyPersonWithRole(PersonWithRole value, String descriptorName) {
super(value, descriptorName);
}
@Override
public void setOnElement(Element element) {
if (getValue() != null)
getValue().setOnElement(element);
}
}
static public class DC {
public interface NAMESPACE extends Property.NAMESPACE {
public static final String URI = "http://purl.org/dc/elements/1.1/";
}
static public class DESCRIPTION extends Property<String> implements NAMESPACE {
public DESCRIPTION() {
}
public DESCRIPTION(String value) {
super(value, null);
}
}
static public class PUBLISHER extends Property<Person> implements NAMESPACE {
public PUBLISHER() {
}
public PUBLISHER(Person value) {
super(value, null);
}
}
static public class CONTRIBUTOR extends Property<Person> implements NAMESPACE {
public CONTRIBUTOR() {
}
public CONTRIBUTOR(Person value) {
super(value, null);
}
}
static public class DATE extends Property<String> implements NAMESPACE {
public DATE() {
}
public DATE(String value) {
super(value, null);
}
}
static public class LANGUAGE extends Property<String> implements NAMESPACE {
public LANGUAGE() {
}
public LANGUAGE(String value) {
super(value, null);
}
}
static public class RELATION extends Property<URI> implements NAMESPACE {
public RELATION() {
}
public RELATION(URI value) {
super(value, null);
}
}
static public class RIGHTS extends Property<String> implements NAMESPACE {
public RIGHTS() {
}
public RIGHTS(String value) {
super(value, null);
}
}
}
static public abstract class UPNP {
public interface NAMESPACE extends Property.NAMESPACE {
public static final String URI = "urn:schemas-upnp-org:metadata-1-0/upnp/";
}
static public class ARTIST extends PropertyPersonWithRole implements NAMESPACE {
public ARTIST() {
}
public ARTIST(PersonWithRole value) {
super(value, null);
}
}
static public class ACTOR extends PropertyPersonWithRole implements NAMESPACE {
public ACTOR() {
}
public ACTOR(PersonWithRole value) {
super(value, null);
}
}
static public class AUTHOR extends PropertyPersonWithRole implements NAMESPACE {
public AUTHOR() {
}
public AUTHOR(PersonWithRole value) {
super(value, null);
}
}
static public class PRODUCER extends Property<Person> implements NAMESPACE {
public PRODUCER() {
}
public PRODUCER(Person value) {
super(value, null);
}
}
static public class DIRECTOR extends Property<Person> implements NAMESPACE {
public DIRECTOR() {
}
public DIRECTOR(Person value) {
super(value, null);
}
}
static public class GENRE extends Property<String> implements NAMESPACE {
public GENRE() {
}
public GENRE(String value) {
super(value, null);
}
}
static public class ALBUM extends Property<String> implements NAMESPACE {
public ALBUM() {
}
public ALBUM(String value) {
super(value, null);
}
}
static public class PLAYLIST extends Property<String> implements NAMESPACE {
public PLAYLIST() {
}
public PLAYLIST(String value) {
super(value, null);
}
}
static public class REGION extends Property<String> implements NAMESPACE {
public REGION() {
}
public REGION(String value) {
super(value, null);
}
}
static public class RATING extends Property<String> implements NAMESPACE {
public RATING() {
}
public RATING(String value) {
super(value, null);
}
}
static public class TOC extends Property<String> implements NAMESPACE {
public TOC() {
}
public TOC(String value) {
super(value, null);
}
}
static public class ALBUM_ART_URI extends Property<URI> implements NAMESPACE {
public ALBUM_ART_URI() {
this(null);
}
public ALBUM_ART_URI(URI value) {
super(value, "albumArtURI");
}
public ALBUM_ART_URI(URI value, List<Property<DIDLAttribute>> attributes) {
super(value, "albumArtURI", attributes);
}
}
static public class ARTIST_DISCO_URI extends Property<URI> implements NAMESPACE {
public ARTIST_DISCO_URI() {
this(null);
}
public ARTIST_DISCO_URI(URI value) {
super(value, "artistDiscographyURI");
}
}
static public class LYRICS_URI extends Property<URI> implements NAMESPACE {
public LYRICS_URI() {
this(null);
}
public LYRICS_URI(URI value) {
super(value, "lyricsURI");
}
}
static public class STORAGE_TOTAL extends Property<Long> implements NAMESPACE {
public STORAGE_TOTAL() {
this(null);
}
public STORAGE_TOTAL(Long value) {
super(value, "storageTotal");
}
}
static public class STORAGE_USED extends Property<Long> implements NAMESPACE {
public STORAGE_USED() {
this(null);
}
public STORAGE_USED(Long value) {
super(value, "storageUsed");
}
}
static public class STORAGE_FREE extends Property<Long> implements NAMESPACE {
public STORAGE_FREE() {
this(null);
}
public STORAGE_FREE(Long value) {
super(value, "storageFree");
}
}
static public class STORAGE_MAX_PARTITION extends Property<Long> implements NAMESPACE {
public STORAGE_MAX_PARTITION() {
this(null);
}
public STORAGE_MAX_PARTITION(Long value) {
super(value, "storageMaxPartition");
}
}
static public class STORAGE_MEDIUM extends Property<StorageMedium> implements NAMESPACE {
public STORAGE_MEDIUM() {
this(null);
}
public STORAGE_MEDIUM(StorageMedium value) {
super(value, "storageMedium");
}
}
static public class LONG_DESCRIPTION extends Property<String> implements NAMESPACE {
public LONG_DESCRIPTION() {
this(null);
}
public LONG_DESCRIPTION(String value) {
super(value, "longDescription");
}
}
static public class ICON extends Property<URI> implements NAMESPACE {
public ICON() {
}
public ICON(URI value) {
super(value, null);
}
}
static public class RADIO_CALL_SIGN extends Property<String> implements NAMESPACE {
public RADIO_CALL_SIGN() {
this(null);
}
public RADIO_CALL_SIGN(String value) {
super(value, "radioCallSign");
}
}
static public class RADIO_STATION_ID extends Property<String> implements NAMESPACE {
public RADIO_STATION_ID() {
this(null);
}
public RADIO_STATION_ID(String value) {
super(value, "radioStationID");
}
}
static public class RADIO_BAND extends Property<String> implements NAMESPACE {
public RADIO_BAND() {
this(null);
}
public RADIO_BAND(String value) {
super(value, "radioBand");
}
}
static public class CHANNEL_NR extends Property<Integer> implements NAMESPACE {
public CHANNEL_NR() {
this(null);
}
public CHANNEL_NR(Integer value) {
super(value, "channelNr");
}
}
static public class CHANNEL_NAME extends Property<String> implements NAMESPACE {
public CHANNEL_NAME() {
this(null);
}
public CHANNEL_NAME(String value) {
super(value, "channelName");
}
}
static public class SCHEDULED_START_TIME extends Property<String> implements NAMESPACE {
public SCHEDULED_START_TIME() {
this(null);
}
public SCHEDULED_START_TIME(String value) {
super(value, "scheduledStartTime");
}
}
static public class SCHEDULED_END_TIME extends Property<String> implements NAMESPACE {
public SCHEDULED_END_TIME() {
this(null);
}
public SCHEDULED_END_TIME(String value) {
super(value, "scheduledEndTime");
}
}
static public class DVD_REGION_CODE extends Property<Integer> implements NAMESPACE {
public DVD_REGION_CODE() {
this(null);
}
public DVD_REGION_CODE(Integer value) {
super(value, "DVDRegionCode");
}
}
static public class ORIGINAL_TRACK_NUMBER extends Property<Integer> implements NAMESPACE {
public ORIGINAL_TRACK_NUMBER() {
this(null);
}
public ORIGINAL_TRACK_NUMBER(Integer value) {
super(value, "originalTrackNumber");
}
}
static public class USER_ANNOTATION extends Property<String> implements NAMESPACE {
public USER_ANNOTATION() {
this(null);
}
public USER_ANNOTATION(String value) {
super(value, "userAnnotation");
}
}
}
static public abstract class DLNA {
public interface NAMESPACE extends Property.NAMESPACE {
public static final String URI = "urn:schemas-dlna-org:metadata-1-0/";
}
static public class PROFILE_ID extends Property<DIDLAttribute> implements NAMESPACE {
public PROFILE_ID() {
this(null);
}
public PROFILE_ID(DIDLAttribute value) {
super(value, "profileID");
}
}
}
}
public static class Class {
protected String value;
protected String friendlyName;
protected boolean includeDerived;
public Class() {
}
public Class(String value) {
this.value = value;
}
public Class(String value, String friendlyName) {
this.value = value;
this.friendlyName = friendlyName;
}
public Class(String value, String friendlyName, boolean includeDerived) {
this.value = value;
this.friendlyName = friendlyName;
this.includeDerived = includeDerived;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getFriendlyName() {
return friendlyName;
}
public void setFriendlyName(String friendlyName) {
this.friendlyName = friendlyName;
}
public boolean isIncludeDerived() {
return includeDerived;
}
public void setIncludeDerived(boolean includeDerived) {
this.includeDerived = includeDerived;
}
public boolean equals(DIDLObject instance) {
return getValue().equals(instance.getClazz().getValue());
}
}
protected String id;
protected String parentID;
protected String title; // DC
protected String creator; // DC
protected boolean restricted = true; // Let's just assume read-only is default
protected WriteStatus writeStatus; // UPNP
protected Class clazz; // UPNP
protected List<Res> resources = new ArrayList();
protected List<Property> properties = new ArrayList();
protected List<DescMeta> descMetadata = new ArrayList();
protected DIDLObject() {
}
protected DIDLObject(DIDLObject other) {
this(other.getId(),
other.getParentID(),
other.getTitle(),
other.getCreator(),
other.isRestricted(),
other.getWriteStatus(),
other.getClazz(),
other.getResources(),
other.getProperties(),
other.getDescMetadata()
);
}
protected DIDLObject(String id, String parentID, String title, String creator, boolean restricted, WriteStatus writeStatus, Class clazz, List<Res> resources, List<Property> properties, List<DescMeta> descMetadata) {
this.id = id;
this.parentID = parentID;
this.title = title;
this.creator = creator;
this.restricted = restricted;
this.writeStatus = writeStatus;
this.clazz = clazz;
this.resources = resources;
this.properties = properties;
this.descMetadata = descMetadata;
}
public String getId() {
return id;
}
public DIDLObject setId(String id) {
this.id = id;
return this;
}
public String getParentID() {
return parentID;
}
public DIDLObject setParentID(String parentID) {
this.parentID = parentID;
return this;
}
public String getTitle() {
return title;
}
public DIDLObject setTitle(String title) {
this.title = title;
return this;
}
public String getCreator() {
return creator;
}
public DIDLObject setCreator(String creator) {
this.creator = creator;
return this;
}
public boolean isRestricted() {
return restricted;
}
public DIDLObject setRestricted(boolean restricted) {
this.restricted = restricted;
return this;
}
public WriteStatus getWriteStatus() {
return writeStatus;
}
public DIDLObject setWriteStatus(WriteStatus writeStatus) {
this.writeStatus = writeStatus;
return this;
}
public Res getFirstResource() {
return getResources().size() > 0 ? getResources().get(0) : null;
}
public List<Res> getResources() {
return resources;
}
public DIDLObject setResources(List<Res> resources) {
this.resources = resources;
return this;
}
public DIDLObject addResource(Res resource) {
getResources().add(resource);
return this;
}
public Class getClazz() {
return clazz;
}
public DIDLObject setClazz(Class clazz) {
this.clazz = clazz;
return this;
}
public List<Property> getProperties() {
return properties;
}
public DIDLObject setProperties(List<Property> properties) {
this.properties = properties;
return this;
}
public DIDLObject addProperty(Property property) {
if (property == null) return this;
getProperties().add(property);
return this;
}
public DIDLObject replaceFirstProperty(Property property) {
if (property == null) return this;
Iterator<Property> it = getProperties().iterator();
while (it.hasNext()) {
Property p = it.next();
if (p.getClass().isAssignableFrom(property.getClass()))
it.remove();
}
addProperty(property);
return this;
}
public DIDLObject replaceProperties(java.lang.Class<? extends Property> propertyClass, Property[] properties) {
if (properties.length == 0) return this;
removeProperties(propertyClass);
return addProperties(properties);
}
public DIDLObject addProperties(Property[] properties) {
if (properties == null) return this;
for (Property property : properties) {
addProperty(property);
}
return this;
}
public DIDLObject removeProperties(java.lang.Class<? extends Property> propertyClass) {
Iterator<Property> it = getProperties().iterator();
while (it.hasNext()) {
Property p = it.next();
if (p.getClass().isAssignableFrom(propertyClass))
it.remove();
}
return this;
}
public boolean hasProperty(java.lang.Class<? extends Property> propertyClass) {
for (Property property : getProperties()) {
if (property.getClass().isAssignableFrom(propertyClass)) return true;
}
return false;
}
public <V> Property<V> getFirstProperty(java.lang.Class<? extends Property<V>> propertyClass) {
for (Property property : getProperties()) {
if (property.getClass().isAssignableFrom(propertyClass)) return property;
}
return null;
}
public <V> Property<V> getLastProperty(java.lang.Class<? extends Property<V>> propertyClass) {
Property found = null;
for (Property property : getProperties()) {
if (property.getClass().isAssignableFrom(propertyClass)) found = property;
}
return found;
}
public <V> Property<V>[] getProperties(java.lang.Class<? extends Property<V>> propertyClass) {
List<Property<V>> list = new ArrayList();
for (Property property : getProperties()) {
if (property.getClass().isAssignableFrom(propertyClass))
list.add(property);
}
return list.toArray(new Property[list.size()]);
}
public <V> Property<V>[] getPropertiesByNamespace(java.lang.Class<? extends Property.NAMESPACE> namespace) {
List<Property<V>> list = new ArrayList();
for (Property property : getProperties()) {
if (namespace.isAssignableFrom(property.getClass()))
list.add(property);
}
return list.toArray(new Property[list.size()]);
}
public <V> V getFirstPropertyValue(java.lang.Class<? extends Property<V>> propertyClass) {
Property<V> prop = getFirstProperty(propertyClass);
return prop == null ? null : prop.getValue();
}
public <V> List<V> getPropertyValues(java.lang.Class<? extends Property<V>> propertyClass) {
List<V> list = new ArrayList();
for (Property property : getProperties(propertyClass)) {
list.add((V) property.getValue());
}
return list;
}
public List<DescMeta> getDescMetadata() {
return descMetadata;
}
public void setDescMetadata(List<DescMeta> descMetadata) {
this.descMetadata = descMetadata;
}
public DIDLObject addDescMetadata(DescMeta descMetadata) {
getDescMetadata().add(descMetadata);
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DIDLObject that = (DIDLObject) o;
if (!id.equals(that.id)) return false;
return true;
}
@Override
public int hashCode() {
return id.hashCode();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/DIDLObject.java | Java | asf20 | 25,506 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
*
*/
public class VolumeDBRange {
private Short minValue;
private Short maxValue;
public VolumeDBRange(Short minValue, Short maxValue) {
this.minValue = minValue;
this.maxValue = maxValue;
}
public Short getMinValue() {
return minValue;
}
public Short getMaxValue() {
return maxValue;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/VolumeDBRange.java | Java | asf20 | 1,129 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.ModelUtil;
import org.teleal.cling.model.action.ActionArgumentValue;
import java.util.Map;
/**
* @author Christian Bauer
*/
public class DeviceCapabilities {
private StorageMedium[] playMedia;
private StorageMedium[] recMedia = new StorageMedium[] {StorageMedium.NOT_IMPLEMENTED};
private RecordQualityMode[] recQualityModes = new RecordQualityMode[] {RecordQualityMode.NOT_IMPLEMENTED};
public DeviceCapabilities(Map<String, ActionArgumentValue> args) {
this(
StorageMedium.valueOfCommaSeparatedList((String) args.get("PlayMedia").getValue()),
StorageMedium.valueOfCommaSeparatedList((String) args.get("RecMedia").getValue()),
RecordQualityMode.valueOfCommaSeparatedList((String) args.get("RecQualityModes").getValue())
);
}
public DeviceCapabilities(StorageMedium[] playMedia) {
this.playMedia = playMedia;
}
public DeviceCapabilities(StorageMedium[] playMedia, StorageMedium[] recMedia, RecordQualityMode[] recQualityModes) {
this.playMedia = playMedia;
this.recMedia = recMedia;
this.recQualityModes = recQualityModes;
}
public StorageMedium[] getPlayMedia() {
return playMedia;
}
public StorageMedium[] getRecMedia() {
return recMedia;
}
public RecordQualityMode[] getRecQualityModes() {
return recQualityModes;
}
public String getPlayMediaString() {
return ModelUtil.toCommaSeparatedList(playMedia);
}
public String getRecMediaString() {
return ModelUtil.toCommaSeparatedList(recMedia);
}
public String getRecQualityModesString() {
return ModelUtil.toCommaSeparatedList(recQualityModes);
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/DeviceCapabilities.java | Java | asf20 | 2,536 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.common.util.MimeType;
import java.net.URI;
/**
* @author Christian Bauer
*/
public class Res {
protected URI importUri;
protected ProtocolInfo protocolInfo;
protected Long size;
protected String duration;
protected Long bitrate;
protected Long sampleFrequency;
protected Long bitsPerSample;
protected Long nrAudioChannels;
protected Long colorDepth;
protected String protection;
protected String resolution;
protected String value;
public Res() {
}
public Res(MimeType httpGetMimeType, Long size, String duration, Long bitrate, String value) {
this(new ProtocolInfo(httpGetMimeType), size, duration, bitrate, value);
}
public Res(MimeType httpGetMimeType, Long size, String value) {
this(new ProtocolInfo(httpGetMimeType), size, value);
}
public Res(ProtocolInfo protocolInfo, Long size, String value) {
this.protocolInfo = protocolInfo;
this.size = size;
this.value = value;
}
public Res(ProtocolInfo protocolInfo, Long size, String duration, Long bitrate, String value) {
this.protocolInfo = protocolInfo;
this.size = size;
this.duration = duration;
this.bitrate = bitrate;
this.value = value;
}
public Res(URI importUri, ProtocolInfo protocolInfo, Long size, String duration, Long bitrate, Long sampleFrequency, Long bitsPerSample, Long nrAudioChannels, Long colorDepth, String protection, String resolution, String value) {
this.importUri = importUri;
this.protocolInfo = protocolInfo;
this.size = size;
this.duration = duration;
this.bitrate = bitrate;
this.sampleFrequency = sampleFrequency;
this.bitsPerSample = bitsPerSample;
this.nrAudioChannels = nrAudioChannels;
this.colorDepth = colorDepth;
this.protection = protection;
this.resolution = resolution;
this.value = value;
}
public URI getImportUri() {
return importUri;
}
public void setImportUri(URI importUri) {
this.importUri = importUri;
}
public ProtocolInfo getProtocolInfo() {
return protocolInfo;
}
public void setProtocolInfo(ProtocolInfo protocolInfo) {
this.protocolInfo = protocolInfo;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
public Long getBitrate() {
return bitrate;
}
public void setBitrate(Long bitrate) {
this.bitrate = bitrate;
}
public Long getSampleFrequency() {
return sampleFrequency;
}
public void setSampleFrequency(Long sampleFrequency) {
this.sampleFrequency = sampleFrequency;
}
public Long getBitsPerSample() {
return bitsPerSample;
}
public void setBitsPerSample(Long bitsPerSample) {
this.bitsPerSample = bitsPerSample;
}
public Long getNrAudioChannels() {
return nrAudioChannels;
}
public void setNrAudioChannels(Long nrAudioChannels) {
this.nrAudioChannels = nrAudioChannels;
}
public Long getColorDepth() {
return colorDepth;
}
public void setColorDepth(Long colorDepth) {
this.colorDepth = colorDepth;
}
public String getProtection() {
return protection;
}
public void setProtection(String protection) {
this.protection = protection;
}
public String getResolution() {
return resolution;
}
public void setResolution(String resolution) {
this.resolution = resolution;
}
public void setResolution(int x, int y) {
this.resolution = x + "x" + y;
}
public int getResolutionX() {
return getResolution() != null && getResolution().split("x").length == 2
? Integer.valueOf(getResolution().split("x")[0])
: 0;
}
public int getResolutionY() {
return getResolution() != null && getResolution().split("x").length == 2
? Integer.valueOf(getResolution().split("x")[1])
: 0;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/Res.java | Java | asf20 | 5,226 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import java.util.ArrayList;
import java.util.List;
/**
* @author Christian Bauer
*/
public class SortCriterion {
final protected boolean ascending;
final protected String propertyName;
public SortCriterion(boolean ascending, String propertyName) {
this.ascending = ascending;
this.propertyName = propertyName;
}
public SortCriterion(String criterion) {
this(criterion.startsWith("+"), criterion.substring(1));
if (!(criterion.startsWith("-") || criterion.startsWith("+")))
throw new IllegalArgumentException("Missing sort prefix +/- on criterion: " + criterion);
}
public boolean isAscending() {
return ascending;
}
public String getPropertyName() {
return propertyName;
}
public static SortCriterion[] valueOf(String s) {
if (s == null || s.length() == 0) return new SortCriterion[0];
List<SortCriterion> list = new ArrayList();
String[] criteria = s.split(",");
for (String criterion : criteria) {
list.add(new SortCriterion(criterion.trim()));
}
return list.toArray(new SortCriterion[list.size()]);
}
public static String toString(SortCriterion[] criteria) {
if (criteria == null) return "";
StringBuilder sb = new StringBuilder();
for (SortCriterion sortCriterion : criteria) {
sb.append(sortCriterion.toString()).append(",");
}
if (sb.toString().endsWith(",")) sb.deleteCharAt(sb.length()-1);
return sb.toString();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(ascending ? "+" : "-");
sb.append(propertyName);
return sb.toString();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/SortCriterion.java | Java | asf20 | 2,541 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.ServiceReference;
/**
* Immutable type encapsulating the state of a single connection.
*
* @author Alessio Gaeta
* @author Christian Bauer
*/
public class ConnectionInfo {
public enum Status {
OK,
ContentFormatMismatch,
InsufficientBandwidth,
UnreliableChannel,
Unknown
}
public enum Direction {
Output,
Input;
public Direction getOpposite() {
return this.equals(Output) ? Input : Output;
}
}
final protected int connectionID;
final protected int rcsID;
final protected int avTransportID;
final protected ProtocolInfo protocolInfo;
final protected ServiceReference peerConnectionManager;
final protected int peerConnectionID;
final protected Direction direction;
protected Status connectionStatus = Status.Unknown;
/**
* Creates a default instance with values expected for the default connection ID "0".
* <p>
* The ConnectionManager 1.0 specification says:
* </p>
* <p>
* If optional action PrepareForConnection is not implemented then (limited) connection
* information can be retrieved for ConnectionID 0. The device should return all known
* information:
* </p>
* <ul>
* <li>RcsID should be 0 or -1</li>
* <li>AVTransportID should be 0 or -1</li>
* <li>ProtocolInfo should contain accurate information if it is known, otherwhise
* it should be NULL (empty string)</li>
* <li>PeerConnectionManager should be NULL (empty string)</li>
* <li>PeerConnectionID should be -1</li>
* <li>Direction should be Input or Output</li>
* <li>Status should be OK or Unknown</li>
* </ul>
*/
public ConnectionInfo() {
this(0, 0, 0, null, null, -1, Direction.Input, Status.Unknown);
}
public ConnectionInfo(int connectionID,
int rcsID, int avTransportID,
ProtocolInfo protocolInfo,
ServiceReference peerConnectionManager, int peerConnectionID,
Direction direction, Status connectionStatus) {
this.connectionID = connectionID;
this.rcsID = rcsID;
this.avTransportID = avTransportID;
this.protocolInfo = protocolInfo;
this.peerConnectionManager = peerConnectionManager;
this.peerConnectionID = peerConnectionID;
this.direction = direction;
this.connectionStatus = connectionStatus;
}
public int getConnectionID() {
return connectionID;
}
public int getRcsID() {
return rcsID;
}
public int getAvTransportID() {
return avTransportID;
}
public ProtocolInfo getProtocolInfo() {
return protocolInfo;
}
public ServiceReference getPeerConnectionManager() {
return peerConnectionManager;
}
public int getPeerConnectionID() {
return peerConnectionID;
}
public Direction getDirection() {
return direction;
}
synchronized public Status getConnectionStatus() {
return connectionStatus;
}
synchronized public void setConnectionStatus(Status connectionStatus) {
this.connectionStatus = connectionStatus;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConnectionInfo that = (ConnectionInfo) o;
if (avTransportID != that.avTransportID) return false;
if (connectionID != that.connectionID) return false;
if (peerConnectionID != that.peerConnectionID) return false;
if (rcsID != that.rcsID) return false;
if (connectionStatus != that.connectionStatus) return false;
if (direction != that.direction) return false;
if (peerConnectionManager != null ? !peerConnectionManager.equals(that.peerConnectionManager) : that.peerConnectionManager != null)
return false;
if (protocolInfo != null ? !protocolInfo.equals(that.protocolInfo) : that.protocolInfo != null) return false;
return true;
}
@Override
public int hashCode() {
int result = connectionID;
result = 31 * result + rcsID;
result = 31 * result + avTransportID;
result = 31 * result + (protocolInfo != null ? protocolInfo.hashCode() : 0);
result = 31 * result + (peerConnectionManager != null ? peerConnectionManager.hashCode() : 0);
result = 31 * result + peerConnectionID;
result = 31 * result + direction.hashCode();
result = 31 * result + connectionStatus.hashCode();
return result;
}
@Override
public String toString() {
return "(" + getClass().getSimpleName() + ") ID: " + getConnectionID() + ", Status: " + getConnectionStatus();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/ConnectionInfo.java | Java | asf20 | 5,671 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
*
*/
public enum PlayMode {
NORMAL,
SHUFFLE,
REPEAT_ONE,
REPEAT_ALL,
RANDOM,
DIRECT_1,
INTRO
}
| zzh84615-mycode | src/org/teleal/cling/support/model/PlayMode.java | Java | asf20 | 895 |
/*
* Copyright (C) 2011 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.teleal.cling.model.ModelUtil;
import org.teleal.cling.model.action.ActionArgumentValue;
import org.teleal.cling.model.types.UnsignedIntegerFourBytes;
import java.util.Map;
/**
* @author Christian Bauer
*/
public class PositionInfo {
private UnsignedIntegerFourBytes track = new UnsignedIntegerFourBytes(0);
private String trackDuration = "00:00:00";
private String trackMetaData = "NOT_IMPLEMENTED";
private String trackURI = "";
private String relTime = "00:00:00";
private String absTime = "00:00:00"; // TODO: MORE VALUES IN DOMAIN!
private int relCount = Integer.MAX_VALUE; // Indicates that we don't support this
private int absCount = Integer.MAX_VALUE;
public PositionInfo() {
}
public PositionInfo(Map<String, ActionArgumentValue> args) {
this(
((UnsignedIntegerFourBytes) args.get("Track").getValue()).getValue(),
(String) args.get("TrackDuration").getValue(),
(String) args.get("TrackMetaData").getValue(),
(String) args.get("TrackURI").getValue(),
(String) args.get("RelTime").getValue(),
(String) args.get("AbsTime").getValue(),
(Integer) args.get("RelCount").getValue(),
(Integer) args.get("AbsCount").getValue()
);
}
public PositionInfo(PositionInfo copy, String relTime, String absTime) {
this.track = copy.track;
this.trackDuration = copy.trackDuration;
this.trackMetaData = copy.trackMetaData;
this.trackURI = copy.trackURI;
this.relTime = relTime;
this.absTime = absTime;
this.relCount = copy.relCount;
this.absCount = copy.absCount;
}
public PositionInfo(PositionInfo copy, long relTimeSeconds, long absTimeSeconds) {
this.track = copy.track;
this.trackDuration = copy.trackDuration;
this.trackMetaData = copy.trackMetaData;
this.trackURI = copy.trackURI;
this.relTime = ModelUtil.toTimeString(relTimeSeconds);
this.absTime = ModelUtil.toTimeString(absTimeSeconds);
this.relCount = copy.relCount;
this.absCount = copy.absCount;
}
public PositionInfo(long track, String trackDuration, String trackURI,
String relTime, String absTime) {
this.track = new UnsignedIntegerFourBytes(track);
this.trackDuration = trackDuration;
this.trackURI = trackURI;
this.relTime = relTime;
this.absTime = absTime;
}
public PositionInfo(long track, String trackDuration,
String trackMetaData, String trackURI,
String relTime, String absTime, int relCount, int absCount) {
this.track = new UnsignedIntegerFourBytes(track);
this.trackDuration = trackDuration;
this.trackMetaData = trackMetaData;
this.trackURI = trackURI;
this.relTime = relTime;
this.absTime = absTime;
this.relCount = relCount;
this.absCount = absCount;
}
public PositionInfo(long track, String trackMetaData, String trackURI) {
this.track = new UnsignedIntegerFourBytes(track);
this.trackMetaData = trackMetaData;
this.trackURI = trackURI;
}
public UnsignedIntegerFourBytes getTrack() {
return track;
}
public String getTrackDuration() {
return trackDuration;
}
public String getTrackMetaData() {
return trackMetaData;
}
public String getTrackURI() {
return trackURI;
}
public String getRelTime() {
return relTime;
}
public String getAbsTime() {
return absTime;
}
public int getRelCount() {
return relCount;
}
public int getAbsCount() {
return absCount;
}
public long getTrackDurationSeconds() {
return getTrackDuration() == null ? 0 : ModelUtil.fromTimeString(getTrackDuration());
}
public long getTrackElapsedSeconds() {
return getRelTime() == null || getRelTime().equals("NOT_IMPLEMENTED") ? 0 : ModelUtil.fromTimeString(getRelTime());
}
public long getTrackRemainingSeconds() {
return getTrackDurationSeconds() - getTrackElapsedSeconds();
}
public int getElapsedPercent() {
long elapsed = getTrackElapsedSeconds();
long total = getTrackDurationSeconds();
if (elapsed == 0 || total == 0) return 0;
return new Double(elapsed/((double)total/100)).intValue();
}
@Override
public String toString() {
return "(PositionInfo) Track: " + getTrack() + " RelTime: " + getRelTime() + " Duration: " + getTrackDuration() + " Percent: " + getElapsedPercent();
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/PositionInfo.java | Java | asf20 | 5,518 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/*
ui4 (ABS_COUNT, REL_COUNT, TRACK_NR, TAPE-INDEX, FRAME)
time (ABS_TIME, REL_TIME)
float (CHANNEL_FREQ, in Hz)
*/
public enum SeekMode {
TRACK_NR("TRACK_NR"),
ABS_TIME("ABS_TIME"),
REL_TIME("REL_TIME"),
ABS_COUNT("ABS_COUNT"),
REL_COUNT("REL_COUNT"),
CHANNEL_FREQ("CHANNEL_FREQ"),
TAPE_INDEX("TAPE-INDEX"),
FRAME("FRAME");
private String protocolString;
SeekMode(String protocolString) {
this.protocolString = protocolString;
}
@Override
public String toString() {
return protocolString;
}
public static SeekMode valueOrExceptionOf(String s) throws IllegalArgumentException {
for (SeekMode seekMode : values()) {
if (seekMode.protocolString.equals(s)) {
return seekMode;
}
}
throw new IllegalArgumentException("Invalid seek mode string: " + s);
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/SeekMode.java | Java | asf20 | 1,683 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
import org.w3c.dom.Element;
/**
* @author Christian Bauer
*/
public class PersonWithRole extends Person {
private String role;
public PersonWithRole(String name) {
super(name);
}
public PersonWithRole(String name, String role) {
super(name);
this.role = role;
}
public String getRole() {
return role;
}
public void setOnElement(Element element) {
element.setTextContent(toString());
element.setAttribute("role", getRole());
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/PersonWithRole.java | Java | asf20 | 1,286 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model;
/**
*
*/
public enum RecordMediumWriteStatus {
WRITABLE,
PROTECTED,
NOT_WRITABLE,
UNKNOWN,
NOT_IMPLEMENTED;
static public RecordMediumWriteStatus valueOrUnknownOf(String s) {
try {
return valueOf(s);
} catch (IllegalArgumentException ex) {
return UNKNOWN;
}
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/RecordMediumWriteStatus.java | Java | asf20 | 1,108 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.item;
import org.teleal.cling.support.model.Res;
import org.teleal.cling.support.model.container.Container;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class Photo extends ImageItem {
public static final Class CLASS = new Class("object.item.imageItem.photo");
public Photo() {
setClazz(CLASS);
}
public Photo(Item other) {
super(other);
}
public Photo(String id, Container parent, String title, String creator, String album, Res... resource) {
this(id, parent.getId(), title, creator, album, resource);
}
public Photo(String id, String parentID, String title, String creator, String album, Res... resource) {
super(id, parentID, title, creator, resource);
setClazz(CLASS);
if (album != null)
setAlbum(album);
}
public String getAlbum() {
return getFirstPropertyValue(UPNP.ALBUM.class);
}
public Photo setAlbum(String album) {
replaceFirstProperty(new UPNP.ALBUM(album));
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/item/Photo.java | Java | asf20 | 1,869 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.item;
import org.teleal.cling.support.model.Person;
import org.teleal.cling.support.model.PersonWithRole;
import org.teleal.cling.support.model.Res;
import org.teleal.cling.support.model.StorageMedium;
import org.teleal.cling.support.model.container.Container;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import static org.teleal.cling.support.model.DIDLObject.Property.DC;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class TextItem extends Item {
public static final Class CLASS = new Class("object.item.textItem");
public TextItem() {
setClazz(CLASS);
}
public TextItem(Item other) {
super(other);
}
public TextItem(String id, Container parent, String title, String creator, Res... resource) {
this(id, parent.getId(), title, creator, resource);
}
public TextItem(String id, String parentID, String title, String creator, Res... resource) {
super(id, parentID, title, creator, CLASS);
if (resource != null) {
getResources().addAll(Arrays.asList(resource));
}
}
public PersonWithRole getFirstAuthor() {
return getFirstPropertyValue(UPNP.AUTHOR.class);
}
public PersonWithRole[] getAuthors() {
List<PersonWithRole> list = getPropertyValues(UPNP.AUTHOR.class);
return list.toArray(new PersonWithRole[list.size()]);
}
public TextItem setAuthors(PersonWithRole[] persons) {
removeProperties(UPNP.AUTHOR.class);
for (PersonWithRole p: persons) {
addProperty(new UPNP.AUTHOR(p));
}
return this;
}
public String getDescription() {
return getFirstPropertyValue(DC.DESCRIPTION.class);
}
public TextItem setDescription(String description) {
replaceFirstProperty(new DC.DESCRIPTION(description));
return this;
}
public String getLongDescription() {
return getFirstPropertyValue(UPNP.LONG_DESCRIPTION.class);
}
public TextItem setLongDescription(String description) {
replaceFirstProperty(new UPNP.LONG_DESCRIPTION(description));
return this;
}
public String getLanguage() {
return getFirstPropertyValue(DC.LANGUAGE.class);
}
public TextItem setLanguage(String language) {
replaceFirstProperty(new DC.LANGUAGE(language));
return this;
}
public StorageMedium getStorageMedium() {
return getFirstPropertyValue(UPNP.STORAGE_MEDIUM.class);
}
public TextItem setStorageMedium(StorageMedium storageMedium) {
replaceFirstProperty(new UPNP.STORAGE_MEDIUM(storageMedium));
return this;
}
public String getDate() {
return getFirstPropertyValue(DC.DATE.class);
}
public TextItem setDate(String date) {
replaceFirstProperty(new DC.DATE(date));
return this;
}
public URI getFirstRelation() {
return getFirstPropertyValue(DC.RELATION.class);
}
public URI[] getRelations() {
List<URI> list = getPropertyValues(DC.RELATION.class);
return list.toArray(new URI[list.size()]);
}
public TextItem setRelations(URI[] relations) {
removeProperties(DC.RELATION.class);
for (URI relation : relations) {
addProperty(new DC.RELATION(relation));
}
return this;
}
public String getFirstRights() {
return getFirstPropertyValue(DC.RIGHTS.class);
}
public String[] getRights() {
List<String> list = getPropertyValues(DC.RIGHTS.class);
return list.toArray(new String[list.size()]);
}
public TextItem setRights(String[] rights) {
removeProperties(DC.RIGHTS.class);
for (String right : rights) {
addProperty(new DC.RIGHTS(right));
}
return this;
}
public String getRating() {
return getFirstPropertyValue(UPNP.RATING.class);
}
public TextItem setRating(String rating) {
replaceFirstProperty(new UPNP.RATING(rating));
return this;
}
public Person getFirstContributor() {
return getFirstPropertyValue(DC.CONTRIBUTOR.class);
}
public Person[] getContributors() {
List<Person> list = getPropertyValues(DC.CONTRIBUTOR.class);
return list.toArray(new Person[list.size()]);
}
public TextItem setContributors(Person[] contributors) {
removeProperties(DC.CONTRIBUTOR.class);
for (Person p : contributors) {
addProperty(new DC.CONTRIBUTOR(p));
}
return this;
}
public Person getFirstPublisher() {
return getFirstPropertyValue(DC.PUBLISHER.class);
}
public Person[] getPublishers() {
List<Person> list = getPropertyValues(DC.PUBLISHER.class);
return list.toArray(new Person[list.size()]);
}
public TextItem setPublishers(Person[] publishers) {
removeProperties(DC.PUBLISHER.class);
for (Person publisher : publishers) {
addProperty(new DC.PUBLISHER(publisher));
}
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/item/TextItem.java | Java | asf20 | 5,915 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.item;
import org.teleal.cling.support.model.Person;
import org.teleal.cling.support.model.Res;
import org.teleal.cling.support.model.StorageMedium;
import org.teleal.cling.support.model.container.Container;
import java.util.Arrays;
import java.util.List;
import static org.teleal.cling.support.model.DIDLObject.Property.DC;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class ImageItem extends Item{
public static final Class CLASS = new Class("object.item.imageItem");
public ImageItem() {
setClazz(CLASS);
}
public ImageItem(Item other) {
super(other);
}
public ImageItem(String id, Container parent, String title, String creator, Res... resource) {
this(id, parent.getId(), title, creator, resource);
}
public ImageItem(String id, String parentID, String title, String creator, Res... resource) {
super(id, parentID, title, creator, CLASS);
if (resource != null) {
getResources().addAll(Arrays.asList(resource));
}
}
public String getDescription() {
return getFirstPropertyValue(DC.DESCRIPTION.class);
}
public ImageItem setDescription(String description) {
replaceFirstProperty(new DC.DESCRIPTION(description));
return this;
}
public String getLongDescription() {
return getFirstPropertyValue(UPNP.LONG_DESCRIPTION.class);
}
public ImageItem setLongDescription(String description) {
replaceFirstProperty(new UPNP.LONG_DESCRIPTION(description));
return this;
}
public Person getFirstPublisher() {
return getFirstPropertyValue(DC.PUBLISHER.class);
}
public Person[] getPublishers() {
List<Person> list = getPropertyValues(DC.PUBLISHER.class);
return list.toArray(new Person[list.size()]);
}
public ImageItem setPublishers(Person[] publishers) {
removeProperties(DC.PUBLISHER.class);
for (Person publisher : publishers) {
addProperty(new DC.PUBLISHER(publisher));
}
return this;
}
public StorageMedium getStorageMedium() {
return getFirstPropertyValue(UPNP.STORAGE_MEDIUM.class);
}
public ImageItem setStorageMedium(StorageMedium storageMedium) {
replaceFirstProperty(new UPNP.STORAGE_MEDIUM(storageMedium));
return this;
}
public String getRating() {
return getFirstPropertyValue(UPNP.RATING.class);
}
public ImageItem setRating(String rating) {
replaceFirstProperty(new UPNP.RATING(rating));
return this;
}
public String getDate() {
return getFirstPropertyValue(DC.DATE.class);
}
public ImageItem setDate(String date) {
replaceFirstProperty(new DC.DATE(date));
return this;
}
public String getFirstRights() {
return getFirstPropertyValue(DC.RIGHTS.class);
}
public String[] getRights() {
List<String> list = getPropertyValues(DC.RIGHTS.class);
return list.toArray(new String[list.size()]);
}
public ImageItem setRights(String[] rights) {
removeProperties(DC.RIGHTS.class);
for (String right : rights) {
addProperty(new DC.RIGHTS(right));
}
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/item/ImageItem.java | Java | asf20 | 4,096 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.item;
import org.teleal.cling.support.model.Person;
import org.teleal.cling.support.model.PersonWithRole;
import org.teleal.cling.support.model.Res;
import org.teleal.cling.support.model.StorageMedium;
import org.teleal.cling.support.model.container.Container;
import java.util.List;
import static org.teleal.cling.support.model.DIDLObject.Property.DC;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class MusicVideoClip extends VideoItem {
public static final Class CLASS = new Class("object.item.videoItem.musicVideoClip");
public MusicVideoClip() {
setClazz(CLASS);
}
public MusicVideoClip(Item other) {
super(other);
}
public MusicVideoClip(String id, Container parent, String title, String creator, Res... resource) {
this(id, parent.getId(), title, creator, resource);
}
public MusicVideoClip(String id, String parentID, String title, String creator, Res... resource) {
super(id, parentID, title, creator, resource);
setClazz(CLASS);
}
public PersonWithRole getFirstArtist() {
return getFirstPropertyValue(UPNP.ARTIST.class);
}
public PersonWithRole[] getArtists() {
List<PersonWithRole> list = getPropertyValues(UPNP.ARTIST.class);
return list.toArray(new PersonWithRole[list.size()]);
}
public MusicVideoClip setArtists(PersonWithRole[] artists) {
removeProperties(UPNP.ARTIST.class);
for (PersonWithRole artist : artists) {
addProperty(new UPNP.ARTIST(artist));
}
return this;
}
public StorageMedium getStorageMedium() {
return getFirstPropertyValue(UPNP.STORAGE_MEDIUM.class);
}
public MusicVideoClip setStorageMedium(StorageMedium storageMedium) {
replaceFirstProperty(new UPNP.STORAGE_MEDIUM(storageMedium));
return this;
}
public String getAlbum() {
return getFirstPropertyValue(UPNP.ALBUM.class);
}
public MusicVideoClip setAlbum(String album) {
replaceFirstProperty(new UPNP.ALBUM(album));
return this;
}
public String getFirstScheduledStartTime() {
return getFirstPropertyValue(UPNP.SCHEDULED_START_TIME.class);
}
public String[] getScheduledStartTimes() {
List<String> list = getPropertyValues(UPNP.SCHEDULED_START_TIME.class);
return list.toArray(new String[list.size()]);
}
public MusicVideoClip setScheduledStartTimes(String[] strings) {
removeProperties(UPNP.SCHEDULED_START_TIME.class);
for (String s : strings) {
addProperty(new UPNP.SCHEDULED_START_TIME(s));
}
return this;
}
public String getFirstScheduledEndTime() {
return getFirstPropertyValue(UPNP.SCHEDULED_END_TIME.class);
}
public String[] getScheduledEndTimes() {
List<String> list = getPropertyValues(UPNP.SCHEDULED_END_TIME.class);
return list.toArray(new String[list.size()]);
}
public MusicVideoClip setScheduledEndTimes(String[] strings) {
removeProperties(UPNP.SCHEDULED_END_TIME.class);
for (String s : strings) {
addProperty(new UPNP.SCHEDULED_END_TIME(s));
}
return this;
}
public Person getFirstContributor() {
return getFirstPropertyValue(DC.CONTRIBUTOR.class);
}
public Person[] getContributors() {
List<Person> list = getPropertyValues(DC.CONTRIBUTOR.class);
return list.toArray(new Person[list.size()]);
}
public MusicVideoClip setContributors(Person[] contributors) {
removeProperties(DC.CONTRIBUTOR.class);
for (Person p : contributors) {
addProperty(new DC.CONTRIBUTOR(p));
}
return this;
}
public String getDate() {
return getFirstPropertyValue(DC.DATE.class);
}
public MusicVideoClip setDate(String date) {
replaceFirstProperty(new DC.DATE(date));
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/item/MusicVideoClip.java | Java | asf20 | 4,790 |
/*
* Copyright (C) 2010 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.model.item;
import org.teleal.cling.support.model.Person;
import org.teleal.cling.support.model.PersonWithRole;
import org.teleal.cling.support.model.Res;
import org.teleal.cling.support.model.StorageMedium;
import org.teleal.cling.support.model.container.Container;
import java.util.List;
import static org.teleal.cling.support.model.DIDLObject.Property.DC;
import static org.teleal.cling.support.model.DIDLObject.Property.UPNP;
/**
* @author Christian Bauer
*/
public class AudioBook extends AudioItem {
public static final Class CLASS = new Class("object.item.audioItem.audioBook");
public AudioBook() {
setClazz(CLASS);
}
public AudioBook(Item other) {
super(other);
}
public AudioBook(String id, Container parent, String title, String creator, Res... resource) {
this(id, parent.getId(), title, creator, null, null, null, resource);
}
public AudioBook(String id, Container parent, String title, String creator, String producer, String contributor, String date, Res... resource) {
this(id, parent.getId(), title, creator, new Person(producer), new Person(contributor), date, resource);
}
public AudioBook(String id, String parentID, String title, String creator, Person producer, Person contributor, String date, Res... resource) {
super(id, parentID, title, creator, resource);
setClazz(CLASS);
if (producer != null)
addProperty(new UPNP.PRODUCER(producer));
if (contributor != null)
addProperty(new DC.CONTRIBUTOR(contributor));
if (date != null)
setDate(date);
}
public StorageMedium getStorageMedium() {
return getFirstPropertyValue(UPNP.STORAGE_MEDIUM.class);
}
public AudioBook setStorageMedium(StorageMedium storageMedium) {
replaceFirstProperty(new UPNP.STORAGE_MEDIUM(storageMedium));
return this;
}
public Person getFirstProducer() {
return getFirstPropertyValue(UPNP.PRODUCER.class);
}
public Person[] getProducers() {
List<Person> list = getPropertyValues(UPNP.PRODUCER.class);
return list.toArray(new Person[list.size()]);
}
public AudioBook setProducers(Person[] persons) {
removeProperties(UPNP.PRODUCER.class);
for (Person p : persons) {
addProperty(new UPNP.PRODUCER(p));
}
return this;
}
public Person getFirstContributor() {
return getFirstPropertyValue(DC.CONTRIBUTOR.class);
}
public Person[] getContributors() {
List<Person> list = getPropertyValues(DC.CONTRIBUTOR.class);
return list.toArray(new Person[list.size()]);
}
public AudioBook setContributors(Person[] contributors) {
removeProperties(DC.CONTRIBUTOR.class);
for (Person p : contributors) {
addProperty(new DC.CONTRIBUTOR(p));
}
return this;
}
public String getDate() {
return getFirstPropertyValue(DC.DATE.class);
}
public AudioBook setDate(String date) {
replaceFirstProperty(new DC.DATE(date));
return this;
}
}
| zzh84615-mycode | src/org/teleal/cling/support/model/item/AudioBook.java | Java | asf20 | 3,902 |