You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by rj...@apache.org on 2009/06/09 14:50:47 UTC
svn commit: r782980 [3/8] - in
/directory/sandbox/slp/src/main/java/org/apache/directory/slp: ./ codec/
extensions/ impl/ impl/da/ impl/filter/ messages/
Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AdvertiserImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AdvertiserImpl.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AdvertiserImpl.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AdvertiserImpl.java Tue Jun 9 12:50:45 2009
@@ -119,22 +119,22 @@
*/
public void register(final ServiceURL url, final List scopes,
final Dictionary attributes) throws ServiceLocationException {
- ServiceRegistrationMessage reg = new ServiceRegistrationMessage();
+ final ServiceRegistrationMessage reg = new ServiceRegistrationMessage();
reg.setServiceURL(url);
reg.setServiceType(url.getServiceType());
if (scopes != null) {
reg.setScopes((String[]) scopes.toArray());
}
- reg.setAttrList((String[]) SLPUtils.dictToAttrList(attributes).toArray(
+ reg.setAttrList(SLPUtils.dictToAttrList(attributes).toArray(
new String[] {}));
reg.setLocale(locale);
InetAddress addr;
try {
addr = InetAddress.getLocalHost();
- } catch (UnknownHostException e) {
+ } catch (final UnknownHostException e) {
addr = SLPCore.getMyIP();
}
- ServiceAcknowledgementMessage ack = (ServiceAcknowledgementMessage) SLPCore
+ final ServiceAcknowledgementMessage ack = (ServiceAcknowledgementMessage) SLPCore
.sendUnicastMessage(reg, new InetSocketAddress(addr
.getHostAddress(), SLPCore.SLP_PORT), true);
@@ -142,7 +142,7 @@
throw new ServiceLocationException((short) 1, "Registration failed");
}
if (ack.getErrorCode() != 0) {
- throw new ServiceLocationException((short) ack.getErrorCode(),
+ throw new ServiceLocationException(ack.getErrorCode(),
"Registration failed");
}
}
@@ -171,23 +171,23 @@
ServiceLocationException.AUTHENTICATION_FAILED,
"Cannot update an entry with auth blocks set. Need to register anew.");
}
- ServiceRegistrationMessage reg = new ServiceRegistrationMessage();
+ final ServiceRegistrationMessage reg = new ServiceRegistrationMessage();
reg.setServiceURL(url);
reg.setServiceType(url.getServiceType());
if (scopes != null) {
reg.setScopes((String[]) scopes.toArray());
}
- reg.setAttrList((String[]) SLPUtils.dictToAttrList(attributes).toArray(
+ reg.setAttrList(SLPUtils.dictToAttrList(attributes).toArray(
new String[] {}));
reg.setLocale(locale);
reg.setFresh(false);
InetAddress addr;
try {
addr = InetAddress.getLocalHost();
- } catch (UnknownHostException e) {
+ } catch (final UnknownHostException e) {
addr = SLPCore.getMyIP();
}
- ServiceAcknowledgementMessage ack = (ServiceAcknowledgementMessage) SLPCore
+ final ServiceAcknowledgementMessage ack = (ServiceAcknowledgementMessage) SLPCore
.sendUnicastMessage(reg, new InetSocketAddress(addr
.getHostAddress(), SLPCore.SLP_PORT), true);
@@ -195,7 +195,7 @@
throw new ServiceLocationException((short) 1, "Registration failed");
}
if (ack.getErrorCode() != 0) {
- throw new ServiceLocationException((short) ack.getErrorCode(),
+ throw new ServiceLocationException(ack.getErrorCode(),
"Registration failed");
}
}
@@ -229,20 +229,20 @@
public void deregister(final ServiceURL url, final List<String> scopes)
throws ServiceLocationException {
- ServiceDeregistrationMessage dereg = new ServiceDeregistrationMessage();
+ final ServiceDeregistrationMessage dereg = new ServiceDeregistrationMessage();
dereg.setServiceURL(url);
if (scopes != null && !scopes.isEmpty()) {
- dereg.setScopes((String[]) scopes.toArray(new String[] {}));
+ dereg.setScopes(scopes.toArray(new String[] {}));
}
dereg.setLocale(locale);
InetAddress addr;
try {
addr = InetAddress.getLocalHost();
- } catch (UnknownHostException e) {
+ } catch (final UnknownHostException e) {
addr = SLPCore.getMyIP();
}
- int port = SLPCore.SLP_PORT;
- ServiceAcknowledgementMessage ack = (ServiceAcknowledgementMessage) SLPCore
+ final int port = SLPCore.SLP_PORT;
+ final ServiceAcknowledgementMessage ack = (ServiceAcknowledgementMessage) SLPCore
.sendUnicastMessage(dereg, new InetSocketAddress(addr
.getHostAddress(), port), true);
if (ack == null) {
@@ -251,7 +251,7 @@
"Deregistration failed");
}
if (ack.getErrorCode() != 0) {
- throw new ServiceLocationException((short) ack.getErrorCode(),
+ throw new ServiceLocationException(ack.getErrorCode(),
"Deregistration failed");
}
}
@@ -295,12 +295,12 @@
}
// build the deregistration message
- ServiceDeregistrationMessage dereg = new ServiceDeregistrationMessage();
+ final ServiceDeregistrationMessage dereg = new ServiceDeregistrationMessage();
dereg.setServiceURL(url);
dereg.setLocale(locale);
// set the tags!
- Enumeration keys = attributes.keys();
- List<String> tags = new ArrayList<String>();
+ final Enumeration keys = attributes.keys();
+ final List<String> tags = new ArrayList<String>();
while (keys.hasMoreElements()) {
tags.add(keys.nextElement().toString());
}
@@ -316,11 +316,11 @@
InetAddress addr;
try {
addr = InetAddress.getLocalHost();
- } catch (UnknownHostException e) {
+ } catch (final UnknownHostException e) {
addr = SLPCore.getMyIP();
}
- int port = SLPCore.SLP_PORT;
- ServiceAcknowledgementMessage ack = (ServiceAcknowledgementMessage) SLPCore
+ final int port = SLPCore.SLP_PORT;
+ final ServiceAcknowledgementMessage ack = (ServiceAcknowledgementMessage) SLPCore
.sendUnicastMessage(dereg, new InetSocketAddress(addr
.getHostAddress(), port), true);
if (ack == null) {
@@ -329,7 +329,7 @@
"Attribute deletion failed");
}
if (ack.getErrorCode() != 0) {
- throw new ServiceLocationException((short) ack.getErrorCode(),
+ throw new ServiceLocationException(ack.getErrorCode(),
"Attribute deletion failed");
}
}
Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AttributeReplyFutureImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AttributeReplyFutureImpl.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AttributeReplyFutureImpl.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AttributeReplyFutureImpl.java Tue Jun 9 12:50:45 2009
@@ -37,221 +37,217 @@
public class AttributeReplyFutureImpl extends NonThreadedReplyFuture implements
AttributeReplyFuture {
-
-// List of responses (i.e. message results)
+ // List of responses (i.e. message results)
private final List<SLPAttributeImpl> attributes = new ArrayList<SLPAttributeImpl>();
-
+
// next attribute to return when next() is called
private int nextAttributePosition = 0;
-
+
/**
- * Creates a new AttributeReplyFuture with a timeout of 5x the WaitTime in SLPConfiguration
+ * Creates a new AttributeReplyFuture with a timeout of 5x the WaitTime in
+ * SLPConfiguration
*/
- public AttributeReplyFutureImpl(){
- super(SLPCore.CONFIG.getWaitTime()*5);
+ public AttributeReplyFutureImpl() {
+ super(SLPCore.CONFIG.getWaitTime() * 5);
}
-
-
+
/**
* Creates a new AttributeReplyFuture with the specified lifetime (in ms)
*
* @param lifetime
- * The time until the ReplyFuture is considered done in ms
+ * The time until the ReplyFuture is considered done in ms
*/
- public AttributeReplyFutureImpl(long lifetime){
+ public AttributeReplyFutureImpl(final long lifetime) {
super(lifetime);
}
-
-
-
+
/**
- * Creates a new AttributeReplyFuture with the specified lifetime (in ms) expecting responses
- * for the specified scopes.
+ * Creates a new AttributeReplyFuture with the specified lifetime (in ms)
+ * expecting responses for the specified scopes.
*
* @param lifetime
- * The lifetime in ms
+ * The lifetime in ms
* @param scopes
- * The scopes for which replies are expected. used for completion checks
- */
- public AttributeReplyFutureImpl(long lifetime,List<String> scopes){
+ * The scopes for which replies are expected. used for completion
+ * checks
+ */
+ public AttributeReplyFutureImpl(final long lifetime,
+ final List<String> scopes) {
super(lifetime, scopes);
}
-
+
@Override
- public void add(AbstractSLPReplyMessage reply){
+ public void add(final AbstractSLPReplyMessage reply) {
- if (reply==null || reply.getErrorCode()!=0){
+ if (reply == null || reply.getErrorCode() != 0) {
return;
}
- if (done){
+ if (done) {
// this reply is coming in too late...
return;
}
-
- synchronized (responders){
+
+ synchronized (responders) {
if (!responders.contains(reply.getSource())) {
responders.add(reply.getSource());
} else {
return;
}
}
-
- if (reply instanceof AttributeReplyMessage){
- for (String s : reply.getResult()){
- try{
- String[] fields = s.split("=");
- String at_name=fields[0];
- if (at_name.startsWith("(")){
- at_name=at_name.substring(1);
+
+ if (reply instanceof AttributeReplyMessage) {
+ for (final String s : reply.getResult()) {
+ try {
+ final String[] fields = s.split("=");
+ String at_name = fields[0];
+ if (at_name.startsWith("(")) {
+ at_name = at_name.substring(1);
}
- if (at_name.endsWith(")")){
- at_name=at_name.substring(0, at_name.length()-1);
+ if (at_name.endsWith(")")) {
+ at_name = at_name.substring(0, at_name.length() - 1);
}
- if (fields.length==1){
- synchronized(attributes){
+ if (fields.length == 1) {
+ synchronized (attributes) {
attributes.add(new SLPAttributeImpl(at_name));
}
} else {
- List<String> vals = SLPUtils.stringToList(fields[1].substring(0,fields[1].length()-1), ",");
- synchronized(attributes){
- attributes.add(new SLPAttributeImpl(at_name,vals));
+ final List<String> vals = SLPUtils.stringToList(
+ fields[1].substring(0, fields[1].length() - 1),
+ ",");
+ synchronized (attributes) {
+ attributes.add(new SLPAttributeImpl(at_name, vals));
}
}
-
-
- } catch (ServiceLocationException sle){
+ } catch (final ServiceLocationException sle) {
continue;
}
}
processExtensions(reply);
-
+
}
-
-
- //stick to the basic behaviour...
- synchronized(responses){
- List<String> res = reply.getResultAsList();
- if (res!=null && res.size()>0){
- List<String> resp = reply.getResultAsList();
- for (String s: resp){
- if (!responses.contains(s)){
+
+ // stick to the basic behaviour...
+ synchronized (responses) {
+ final List<String> res = reply.getResultAsList();
+ if (res != null && res.size() > 0) {
+ final List<String> resp = reply.getResultAsList();
+ for (final String s : resp) {
+ if (!responses.contains(s)) {
responses.add(s);
}
}
responses.notifyAll();
}
}
-
+
}
-
+
/**
* Process the extensions
*
* @param reply
- * The reply message possibly containing extensions
+ * The reply message possibly containing extensions
*
*/
- private void processExtensions(AbstractSLPReplyMessage reply){
- for (AbstractExtension ae : reply.getExtensions()){
- if (ae instanceof UnsupportedExtension){
+ private void processExtensions(final AbstractSLPReplyMessage reply) {
+ for (final AbstractExtension ae : reply.getExtensions()) {
+ if (ae instanceof UnsupportedExtension) {
return;
}
- switch (ae.getId()){
-
-
-
+ switch (ae.getId()) {
+
}
}
}
-
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.AttributeReplyFuture#nextAttribute()
*/
- public SLPAttribute nextAttribute(){
- // NOTE: a future is currently only read by one consumer (i.e. LocatorImpl) and therefor a single
- // position marker is sufficient. Also the data containers holding responses must add new elements to the end.
- synchronized(attributes){
- while (!done){
- if (attributes.size()>nextAttributePosition){
+ public SLPAttribute nextAttribute() {
+ // NOTE: a future is currently only read by one consumer (i.e.
+ // LocatorImpl) and therefor a single
+ // position marker is sufficient. Also the data containers holding
+ // responses must add new elements to the end.
+ synchronized (attributes) {
+ while (!done) {
+ if (attributes.size() > nextAttributePosition) {
return attributes.get(nextAttributePosition++);
}
- try{
- attributes.wait(timeout-System.currentTimeMillis()+1000);
- } catch (InterruptedException e){
-
+ try {
+ attributes
+ .wait(timeout - System.currentTimeMillis() + 1000);
+ } catch (final InterruptedException e) {
+
}
}
- if (attributes.size()>nextAttributePosition){
+ if (attributes.size() > nextAttributePosition) {
return attributes.get(nextAttributePosition++);
}
return null;
}
}
-
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.AttributeReplyFuture#getResultAttributes()
*/
- public List<SLPAttribute> getResultAttributes(){
- while (!done){
- synchronized (donelock){
+ public List<SLPAttribute> getResultAttributes() {
+ while (!done) {
+ synchronized (donelock) {
try {
donelock.wait();
- } catch (InterruptedException ie){
-
+ } catch (final InterruptedException ie) {
+
}
}
}
return mergeAttributes();
}
-
/**
- * Merges the SLPAttributes of the same type.
- * Must be called only when the reply future is done, i.e. all responses are in.
+ * Merges the SLPAttributes of the same type. Must be called only when the
+ * reply future is done, i.e. all responses are in.
*
* @return
*/
- private List<SLPAttribute> mergeAttributes(){
-
- List<SLPAttributeImpl> t_attributes = new ArrayList<SLPAttributeImpl>(attributes);
- List<SLPAttribute> merged = new ArrayList<SLPAttribute>();
- List<String> keywords = new ArrayList<String>();
- while (!t_attributes.isEmpty()){
- SLPAttributeImpl a = t_attributes.get(0);
- if (a.isKeyword()){
- if (!keywords.contains(a.getName())){
- merged.add(a);
- keywords.add(a.getName());
- }
- t_attributes.remove(0);
- } else {
- List<SLPAttributeImpl> remove = new ArrayList<SLPAttributeImpl>();
- for (int i=1;i<t_attributes.size();i++){
- SLPAttributeImpl b = t_attributes.get(i);
- if (b.getName().equals(a.getName()) && b.getType()==a.getType()){
- a.merge(b);
- remove.add(b);
- }
- }
+ private List<SLPAttribute> mergeAttributes() {
+
+ final List<SLPAttributeImpl> t_attributes = new ArrayList<SLPAttributeImpl>(
+ attributes);
+ final List<SLPAttribute> merged = new ArrayList<SLPAttribute>();
+ final List<String> keywords = new ArrayList<String>();
+ while (!t_attributes.isEmpty()) {
+ final SLPAttributeImpl a = t_attributes.get(0);
+ if (a.isKeyword()) {
+ if (!keywords.contains(a.getName())) {
merged.add(a);
- t_attributes.remove(a);
- for (SLPAttributeImpl j:remove){
- t_attributes.remove(j);
+ keywords.add(a.getName());
+ }
+ t_attributes.remove(0);
+ } else {
+ final List<SLPAttributeImpl> remove = new ArrayList<SLPAttributeImpl>();
+ for (int i = 1; i < t_attributes.size(); i++) {
+ final SLPAttributeImpl b = t_attributes.get(i);
+ if (b.getName().equals(a.getName())
+ && b.getType() == a.getType()) {
+ a.merge(b);
+ remove.add(b);
}
}
+ merged.add(a);
+ t_attributes.remove(a);
+ for (final SLPAttributeImpl j : remove) {
+ t_attributes.remove(j);
+ }
}
-
-
- return new ArrayList<SLPAttribute>(merged);
-
-
-
-
- }
+ }
+ return new ArrayList<SLPAttribute>(merged);
+
+ }
-
}
Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AuthenticatedServiceURL.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AuthenticatedServiceURL.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AuthenticatedServiceURL.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AuthenticatedServiceURL.java Tue Jun 9 12:50:45 2009
@@ -34,7 +34,7 @@
public class AuthenticatedServiceURL {
int lifetime = 0;
-
+
/**
* the authentication blocks.
*/
@@ -54,21 +54,19 @@
return authBlocks;
}
-
-
-
/**
* verify the authentication blocks.
*
- * Copied over to the MINA port from the original jSLP implementation, untested
+ * Copied over to the MINA port from the original jSLP implementation,
+ * untested
*/
public void verify() throws ServiceLocationException {
if (authBlocks.length == 0) {
return;
}
for (int i = 0; i < authBlocks.length; i++) {
- byte[] data = getAuthData(authBlocks[i].getSpi(), authBlocks[i]
- .getTimestamp());
+ final byte[] data = getAuthData(authBlocks[i].getSpi(),
+ authBlocks[i].getTimestamp());
if (authBlocks[i].verify(data)) {
return;
}
@@ -103,13 +101,13 @@
dos.write(temp);
dos.writeInt(timestamp);
return bos.toByteArray();
- } catch (IOException ioe) {
+ } catch (final IOException ioe) {
throw new ServiceLocationException(
ServiceLocationException.INTERNAL_SYSTEM_ERROR, ioe
.getMessage());
}
}
-
+
/**
* sign the ServiceURL.
*
@@ -118,62 +116,64 @@
* @throws ServiceLocationException
* in case of IO errors.
*/
- public final void sign(final List spiList)
- throws ServiceLocationException {
+ public final void sign(final List spiList) throws ServiceLocationException {
authBlocks = new AuthenticationBlock[spiList.size()];
for (int k = 0; k < spiList.size(); k++) {
int timestamp = SLPUtils.getTimestamp();
timestamp += lifetime;
- String spi = (String) spiList.get(k);
- byte[] data = getAuthData(spi, timestamp);
+ final String spi = (String) spiList.get(k);
+ final byte[] data = getAuthData(spi, timestamp);
byte[] sig;
try {
- sig = AuthenticationBlock.sign(spi,data);
- } catch (Exception e) {
- //SLPCore.platform.logError(e.getMessage(), e.fillInStackTrace());
+ sig = AuthenticationBlock.sign(spi, data);
+ } catch (final Exception e) {
+ // SLPCore.platform.logError(e.getMessage(),
+ // e.fillInStackTrace());
throw new ServiceLocationException(
ServiceLocationException.AUTHENTICATION_FAILED,
"Could not sign data");
}
- authBlocks[k] = new AuthenticationBlock(timestamp,spi,sig);
-
+ authBlocks[k] = new AuthenticationBlock(timestamp, spi, sig);
+
}
}
-
+
/**
* sign the ServiceURL.
*
- * Copied over to the MINA port from the original jSLP implementation, untested
+ * Copied over to the MINA port from the original jSLP implementation,
+ * untested
*
- * Type mismatch between the original jSLP (all Lists) and the MINA codecs (all String[])
- * required this overload.
+ * Type mismatch between the original jSLP (all Lists) and the MINA codecs
+ * (all String[]) required this overload.
*
* @param spiList
* the String[] of SPIs
* @throws ServiceLocationException
* in case of IO errors.
*/
- public final void sign (final String[] spiList) throws ServiceLocationException{
+ public final void sign(final String[] spiList)
+ throws ServiceLocationException {
authBlocks = new AuthenticationBlock[spiList.length];
- for (int k = 0; k< spiList.length;k++){
+ for (int k = 0; k < spiList.length; k++) {
int timestamp = SLPUtils.getTimestamp();
timestamp += lifetime;
- String spi = (String) spiList[k];
- byte[] data = getAuthData(spi, timestamp);
+ final String spi = spiList[k];
+ final byte[] data = getAuthData(spi, timestamp);
byte[] sig;
try {
- sig = AuthenticationBlock.sign(spi,data);
- } catch (Exception e) {
- //SLPCore.platform.logError(e.getMessage(), e.fillInStackTrace());
+ sig = AuthenticationBlock.sign(spi, data);
+ } catch (final Exception e) {
+ // SLPCore.platform.logError(e.getMessage(),
+ // e.fillInStackTrace());
throw new ServiceLocationException(
ServiceLocationException.AUTHENTICATION_FAILED,
"Could not sign data");
}
- authBlocks[k] = new AuthenticationBlock(timestamp,spi,sig);
+ authBlocks[k] = new AuthenticationBlock(timestamp, spi, sig);
}
}
-
}
Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AuthenticationBlock.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AuthenticationBlock.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AuthenticationBlock.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/AuthenticationBlock.java Tue Jun 9 12:50:45 2009
@@ -27,7 +27,6 @@
import org.apache.directory.slp.ServiceLocationException;
-
/**
* Authentication block.
*
@@ -43,7 +42,7 @@
/**
* the timestamp.
*/
- private int timestamp;
+ private final int timestamp;
/**
* the signature.
@@ -69,24 +68,24 @@
public String getSpi() {
return spi;
}
-
-
+
/**
* sign the AuthenticationBlock.
*
* @throws ServiceLocationException
* in case of processing errors.
*/
- public static byte[] sign(String spi,byte[] data) throws ServiceLocationException {
+ public static byte[] sign(final String spi, final byte[] data)
+ throws ServiceLocationException {
try {
- PrivateKey privateKey = SLPCore.CONFIG.getPrivateKey(spi);
+ final PrivateKey privateKey = SLPCore.CONFIG.getPrivateKey(spi);
SLPCore.platform.logDebug("Signing with SPI: " + spi);
- Signature signature = Signature.getInstance("SHA1withDSA");
+ final Signature signature = Signature.getInstance("SHA1withDSA");
signature.initSign(privateKey);
signature.update(data);
- byte[] sig = signature.sign();
+ final byte[] sig = signature.sign();
return sig;
- } catch (Exception e) {
+ } catch (final Exception e) {
SLPCore.platform.logError(e.getMessage(), e.fillInStackTrace());
throw new ServiceLocationException(
ServiceLocationException.AUTHENTICATION_FAILED,
@@ -94,10 +93,6 @@
}
}
-
-
-
-
/**
* verify the authBlock.
*
@@ -109,18 +104,18 @@
*/
public boolean verify(final byte[] verData) throws ServiceLocationException {
try {
- PublicKey publicKey = SLPCore.CONFIG.getPublicKey(spi);
+ final PublicKey publicKey = SLPCore.CONFIG.getPublicKey(spi);
- Signature signature = Signature.getInstance("SHA1withDSA");
+ final Signature signature = Signature.getInstance("SHA1withDSA");
signature.initVerify(publicKey);
signature.update(verData);
- boolean success = signature.verify(sig);
+ final boolean success = signature.verify(sig);
SLPCore.platform.logDebug((success ? "Verified with SPI: "
- : "Verification failed with SPI: ")
- + spi);
+ : "Verification failed with SPI: ")
+ + spi);
return success;
- } catch (Exception e) {
+ } catch (final Exception e) {
SLPCore.platform.logError(e.getMessage(), e.fillInStackTrace());
throw new ServiceLocationException(
ServiceLocationException.AUTHENTICATION_FAILED,
@@ -131,7 +126,7 @@
public byte[] getSig() {
return sig;
}
-
+
/**
* calculates the length of this auth block.
*
@@ -145,7 +140,7 @@
+ spi.getBytes().length // spi
+ sig.length; // signature
}
-
+
/**
* get the bytes.
*
@@ -157,13 +152,10 @@
out.writeShort(BSD_DSA); // BSD
out.writeShort((short) getLength());
out.writeInt(timestamp);
- byte[] temp = spi.getBytes();
+ final byte[] temp = spi.getBytes();
out.writeShort(temp.length);
out.write(temp);
out.write(sig);
}
-
-
-
-
+
}
Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/LocatorImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/LocatorImpl.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/LocatorImpl.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/LocatorImpl.java Tue Jun 9 12:50:45 2009
@@ -41,7 +41,6 @@
import org.apache.directory.slp.messages.AttributeRequestMessage;
import org.apache.directory.slp.messages.ServiceRequestMessage;
import org.apache.directory.slp.messages.ServiceTypeRequestMessage;
-//import com.sun.slamd.stat.CategoricalTracker;
/**
* Implementation of the Locator interface. If the configuration does not have
@@ -111,22 +110,19 @@
* if something goes wrong.
* @see Locator#findServiceTypes(String, List)
*/
- public ReplyFuture findServiceTypes(
- final String namingAuthority, final List<String> scopes)
- throws ServiceLocationException {
- ServiceTypeRequestMessage srvTypeReq = new ServiceTypeRequestMessage();
+ public ReplyFuture findServiceTypes(final String namingAuthority,
+ final List<String> scopes) throws ServiceLocationException {
+ final ServiceTypeRequestMessage srvTypeReq = new ServiceTypeRequestMessage();
srvTypeReq.setNamingAuthority(namingAuthority);
- if (scopes!=null){
- if (scopes.size()>0){
+ if (scopes != null) {
+ if (scopes.size() > 0) {
srvTypeReq.setScopes(SLPUtils.listToStringArray(scopes));
}
}
srvTypeReq.setLocale(locale);
- return sendRequest(srvTypeReq,scopes);
+ return sendRequest(srvTypeReq, scopes);
}
-
-
/**
* find services.
*
@@ -143,37 +139,37 @@
*/
public ServiceReplyFuture findServices(final ServiceType type,
final List<String> scopes, final String searchFilter)
- throws ServiceLocationException {
+ throws ServiceLocationException {
try {
- ServiceRequestMessage srvReq = new ServiceRequestMessage();
+ final ServiceRequestMessage srvReq = new ServiceRequestMessage();
srvReq.setServiceType(type);
- if (scopes!=null){
- if (scopes.size()>0){
+ if (scopes != null) {
+ if (scopes.size() > 0) {
srvReq.setScopes(SLPUtils.listToStringArray(scopes));
}
}
srvReq.setPredicate(searchFilter);
srvReq.setLocale(locale);
- if (useAttributeListExtension){
- srvReq.addExtension(new AttributeListExtension("",""));
+ if (useAttributeListExtension) {
+ srvReq.addExtension(new AttributeListExtension("", ""));
}
- if (SLPCore.CONFIG.getSecurityEnabled()){
- srvReq.setSPIs(SLPUtils.stringToStringArray(SLPCore.CONFIG.getSPI(), ","));
+ if (SLPCore.CONFIG.getSecurityEnabled()) {
+ srvReq.setSPIs(SLPUtils.stringToStringArray(SLPCore.CONFIG
+ .getSPI(), ","));
}
- return (ServiceReplyFutureImpl) sendRequest(srvReq,scopes);
- } catch (IllegalArgumentException ise) {
+ return (ServiceReplyFutureImpl) sendRequest(srvReq, scopes);
+ } catch (final IllegalArgumentException ise) {
throw new ServiceLocationException(
ServiceLocationException.INTERNAL_SYSTEM_ERROR, ise
- .getMessage()
- + ": " + searchFilter);
+ .getMessage()
+ + ": " + searchFilter);
}
}
-
/**
* find attributes by service URL.
*
@@ -191,11 +187,11 @@
*/
public AttributeReplyFuture findAttributes(final ServiceURL url,
final List scopes, final List attributeIds)
- throws ServiceLocationException {
- AttributeRequestMessage attrReq = new AttributeRequestMessage();
+ throws ServiceLocationException {
+ final AttributeRequestMessage attrReq = new AttributeRequestMessage();
attrReq.setServiceURL(url);
- if (scopes!=null){
- if (scopes.size()>0){
+ if (scopes != null) {
+ if (scopes.size() > 0) {
attrReq.setScopes(SLPUtils.listToStringArray(scopes));
}
}
@@ -221,11 +217,12 @@
*/
public AttributeReplyFuture findAttributes(final ServiceType type,
final List scopes, final List attributeIds)
- throws ServiceLocationException {
- AttributeRequestMessage attrReq = new AttributeRequestMessage();
- attrReq.setServiceURL(new ServiceURL(type,ServiceURL.LIFETIME_DEFAULT));
- if (scopes!=null){
- if (scopes.size()>0){
+ throws ServiceLocationException {
+ final AttributeRequestMessage attrReq = new AttributeRequestMessage();
+ attrReq
+ .setServiceURL(new ServiceURL(type, ServiceURL.LIFETIME_DEFAULT));
+ if (scopes != null) {
+ if (scopes.size() > 0) {
attrReq.setScopes(SLPUtils.listToStringArray(scopes));
}
}
@@ -234,16 +231,15 @@
return findAttributes(attrReq);
}
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.Locator#listenOnSLPPort()
*/
public void listenOnSLPPort() throws ServiceLocationException {
SLPCore.initializeListeners();
}
-
-
/**
* common method that handles a predefined AttributeRequest.
*
@@ -254,46 +250,46 @@
* in case of network errors.
*/
private AttributeReplyFuture findAttributes(
- final AttributeRequestMessage attReq) throws ServiceLocationException {
- return (AttributeReplyFuture) sendRequest(attReq,SLPUtils.arrayToList(attReq.getScopes()));
+ final AttributeRequestMessage attReq)
+ throws ServiceLocationException {
+ return (AttributeReplyFuture) sendRequest(attReq, SLPUtils
+ .arrayToList(attReq.getScopes()));
}
-
-// public void shutdown(){
-// SLPCore.shutdownUserAgent();
-// }
-
-
-
-
+ // public void shutdown(){
+ // SLPCore.shutdownUserAgent();
+ // }
/**
* send a request. Uses direct communication to a DA or multicast
- * convergence, if no DA is known for the specific scope. mcc is ignored when sufficient results are in
+ * convergence, if no DA is known for the specific scope. mcc is ignored
+ * when sufficient results are in
*
* @param req
* the request.
* @param scopeList
* the scopes.
* @param numberOfResults
- * returns when this number of results have been acquired or the mcc ends
+ * returns when this number of results have been acquired or the
+ * mcc ends
* @return the list of results.
* @throws ServiceLocationException
* if something goes wrong.
*/
- private ReplyFuture sendRequest(final AbstractSLPRequestMessage req, final List<String> scopeList)
- throws ServiceLocationException {
- List<String> scopes = scopeList != null ? scopeList : SLPUtils.stringToList(SLPCore.CONFIG.getScopes(),",");
+ private ReplyFuture sendRequest(final AbstractSLPRequestMessage req,
+ final List<String> scopeList) throws ServiceLocationException {
+ final List<String> scopes = scopeList != null ? scopeList : SLPUtils
+ .stringToList(SLPCore.CONFIG.getScopes(), ",");
NonThreadedReplyFuture reply;
- if (req instanceof ServiceRequestMessage){
+ if (req instanceof ServiceRequestMessage) {
reply = new ServiceReplyFutureImpl(10000, scopes);
- } else if (req instanceof AttributeRequestMessage){
+ } else if (req instanceof AttributeRequestMessage) {
reply = new AttributeReplyFutureImpl(10000, scopes);
} else {
reply = new NonThreadedReplyFuture(10000, scopes);
}
- threadPool.execute(new AsynchRequestThread(reply,req,scopes));
+ threadPool.execute(new AsynchRequestThread(reply, req, scopes));
return reply;
}
@@ -308,22 +304,22 @@
* @return the <code>List</code> of results.
* @throws ServiceLocationException
*/
- private static void sendRequestToDA(final ReplyFuture replyfuture, final AbstractSLPRequestMessage req,
+ private static void sendRequestToDA(final ReplyFuture replyfuture,
+ final AbstractSLPRequestMessage req,
final List<String> dAaddresses, final String[] scopes) {
-
- threadPool.execute(new AsynchDAThread(replyfuture,req,dAaddresses, scopes));
- }
+ threadPool.execute(new AsynchDAThread(replyfuture, req, dAaddresses,
+ scopes));
+ }
/**
* Thread responsible for sending a request to one or more DAs
*
* @author breul
- *
+ *
*/
private static class AsynchDAThread implements Runnable {
-
// The reply future to be filled in
private final ReplyFuture replyfuture;
@@ -340,35 +336,39 @@
* The constructor to kick off requests to DAs
*
* @param rf
- * The reply future to be filled in
+ * The reply future to be filled in
* @param req
- * The message to be sent (a request)
+ * The message to be sent (a request)
* @param dAaddresses
- * The List of DA addresses to be contacted
+ * The List of DA addresses to be contacted
*/
- public AsynchDAThread(ReplyFuture rf, AbstractSLPRequestMessage req, List<String> dAaddresses, String[] scopes){
- replyfuture=rf;
- msg=req;
- dAs=dAaddresses;
- this.scopes=scopes;
+ public AsynchDAThread(final ReplyFuture rf,
+ final AbstractSLPRequestMessage req,
+ final List<String> dAaddresses, final String[] scopes) {
+ replyfuture = rf;
+ msg = req;
+ dAs = dAaddresses;
+ this.scopes = scopes;
}
-
public void run() {
- while (dAs.size()>0) {
+ while (dAs.size() > 0) {
int index = 0;
try {
// often there will be only one...
- if (dAs.size()>1){
- index = (int) Math.rint(Math.random()*(dAs.size()-1));
+ if (dAs.size() > 1) {
+ index = (int) Math.rint(Math.random()
+ * (dAs.size() - 1));
}
// set the receiver address
- InetAddress address = InetAddress.getByName((String) dAs
+ final InetAddress address = InetAddress.getByName(dAs
.get(index));
- int port = SLPCore.SLP_PORT;
- AbstractSLPReplyMessage reply = SLPCore.sendReliableUnicastMessage(msg,new InetSocketAddress(address,port) ,true);
- if (reply == null){
+ final int port = SLPCore.SLP_PORT;
+ final AbstractSLPReplyMessage reply = SLPCore
+ .sendReliableUnicastMessage(msg,
+ new InetSocketAddress(address, port), true);
+ if (reply == null) {
// remove DA from list.
final Object url = dAs.get(index);
SLPUtils.removeValueFromAll(SLPCore.dAs, url);
@@ -377,11 +377,12 @@
// Try the next DA in the list.
continue;
}
- // add the reply to the future and mark the scope used as "handled"
+ // add the reply to the future and mark the scope used as
+ // "handled"
replyfuture.add(reply);
break;
- } catch (Exception e) {
+ } catch (final Exception e) {
SLPCore.platform.logError(e.getMessage(), e
.fillInStackTrace());
// something went wrong.
@@ -394,21 +395,20 @@
continue;
}
}
- // mark the reply future as done unless there are still other scopes to be handled.
- replyfuture.setDone(scopes,false);
+ // mark the reply future as done unless there are still other scopes
+ // to be handled.
+ replyfuture.setDone(scopes, false);
}
-}
-
-
-
+ }
/**
- * The thread used to send requests, either to pass them on to DAs or two kick off a multicast convergence
+ * The thread used to send requests, either to pass them on to DAs or two
+ * kick off a multicast convergence
*
* @author breul
- *
+ *
*/
- private static class AsynchRequestThread implements Runnable{
+ private static class AsynchRequestThread implements Runnable {
// The reply future to be filled in
private final ReplyFuture replyfuture;
@@ -419,44 +419,46 @@
// The scopes to handle
private final List<String> scopes;
-
-
/**
* The constructor to start the request
*
* @param rf
- * The reply future to fill in
+ * The reply future to fill in
* @param req
- * The request to send
+ * The request to send
* @param scopelist
- * The list of scopes to be handled
+ * The list of scopes to be handled
*/
- public AsynchRequestThread(ReplyFuture rf, AbstractSLPRequestMessage req, List<String> scopelist){
- replyfuture=rf;
- msg=req;
- scopes=scopelist;
+ public AsynchRequestThread(final ReplyFuture rf,
+ final AbstractSLPRequestMessage req,
+ final List<String> scopelist) {
+ replyfuture = rf;
+ msg = req;
+ scopes = scopelist;
}
- public void run(){
- // if a UA is in multiple scopes, and a DA is also in these multiple scopes, then the UA
- // would send the same request to such DA for each scope. Therefor we keep track
+ public void run() {
+ // if a UA is in multiple scopes, and a DA is also in these multiple
+ // scopes, then the UA
+ // would send the same request to such DA for each scope. Therefor
+ // we keep track
// of DAs that have been contacted.
- List<String> usedDAs = new ArrayList<String>();
+ final List<String> usedDAs = new ArrayList<String>();
boolean scopeOverlap = false;
- for (String scope:scopes) {
+ for (String scope : scopes) {
scope = scope.toLowerCase();
List<String> dAs = SLPCore.dAs.get(scope);
SLPCore.platform
- .logDebug("DAS FOR SCOPE " + scope + ": " + dAs);
+ .logDebug("DAS FOR SCOPE " + scope + ": " + dAs);
// no DA for the scope known ?
// try to find one
if ((dAs == null || dAs.isEmpty()) && !SLPCore.noDiscovery) {
try {
SLPCore.daLookup(new String[] { scope });
- } catch (ServiceLocationException sle){
+ } catch (final ServiceLocationException sle) {
}
@@ -464,20 +466,22 @@
synchronized (SLPCore.dAs) {
try {
SLPCore.dAs.wait(SLPCore.CONFIG.getWaitTime() / 4);
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
SLPCore.platform.logError(e.getMessage(), e);
- // Restore the interrupted status as we're not the owner of the current thread
+ // Restore the interrupted status as we're not the
+ // owner of the current thread
Thread.currentThread().interrupt();
}
}
dAs = SLPCore.dAs.get(scope);
}
- List<String> newDas = new ArrayList<String>();
- // remove those already contacted while handling a previous scope...
- if (dAs!=null){
- for (String s: dAs){
- if (usedDAs.contains(s)){
+ final List<String> newDas = new ArrayList<String>();
+ // remove those already contacted while handling a previous
+ // scope...
+ if (dAs != null) {
+ for (final String s : dAs) {
+ if (usedDAs.contains(s)) {
scopeOverlap = true;
} else {
newDas.add(s);
@@ -486,26 +490,34 @@
}
if (newDas != null && !newDas.isEmpty()) {
- // a DA is known for this scope which has not already been asked in a different scope, so contact it
- sendRequestToDA(replyfuture,msg,newDas, new String[]{scope});
+ // a DA is known for this scope which has not already been
+ // asked in a different scope, so contact it
+ sendRequestToDA(replyfuture, msg, newDas,
+ new String[] { scope });
// add DA to set of used DAs
usedDAs.addAll(newDas);
// reset overlap flag
scopeOverlap = false;
- } else if (scopeOverlap){
- // No new DA around for this scope, as the scope was covered by a previous request
- replyfuture.setDone(new String[]{scope}, false);
+ } else if (scopeOverlap) {
+ // No new DA around for this scope, as the scope was covered
+ // by a previous request
+ replyfuture.setDone(new String[] { scope }, false);
} else {
- // still no DA available and no overlap of scopes and DAs, use multicast
+ // still no DA available and no overlap of scopes and DAs,
+ // use multicast
try {
// TODO: clarify scope handling in MCC
// two possibilities:
- // a: include all scopes in mcc, leading to repeat responses from SAs and DAs in more than one scope, but we can break after only 1 MCC
- // b: send to only a specific scope, possibly leading to multiple rounds of MCC
- // c: add known responders to the initial mcc request to minimize traffic (as done now).
+ // a: include all scopes in mcc, leading to repeat
+ // responses from SAs and DAs in more than one scope,
+ // but we can break after only 1 MCC
+ // b: send to only a specific scope, possibly leading to
+ // multiple rounds of MCC
+ // c: add known responders to the initial mcc request to
+ // minimize traffic (as done now).
msg.setPrevResponders(replyfuture.getResponders());
- SLPCore.multicastConvergence(replyfuture,msg);
- } catch (ServiceLocationException sle){
+ SLPCore.multicastConvergence(replyfuture, msg);
+ } catch (final ServiceLocationException sle) {
continue;
}
@@ -515,23 +527,25 @@
}
-
}
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.Locator#isUseAttributeListExtension()
*/
public boolean isUseAttributeListExtension() {
return useAttributeListExtension;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.Locator#setUseAttributeListExtension(boolean)
*/
- public void setUseAttributeListExtension(boolean useAttributeListExtension) {
+ public void setUseAttributeListExtension(
+ final boolean useAttributeListExtension) {
this.useAttributeListExtension = useAttributeListExtension;
}
-
-
+
}
Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/NonThreadedReplyFuture.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/NonThreadedReplyFuture.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/NonThreadedReplyFuture.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/NonThreadedReplyFuture.java Tue Jun 9 12:50:45 2009
@@ -26,259 +26,259 @@
import org.apache.directory.slp.messages.AbstractSLPReplyMessage;
/**
- * The future returned when performing SLP lookups. It can be accessed while results still come in using next(),
- * or after all results have arrived using getResult().
+ * The future returned when performing SLP lookups. It can be accessed while
+ * results still come in using next(), or after all results have arrived using
+ * getResult().
*
* @author Lorenz Breu
*/
-public class NonThreadedReplyFuture implements ReplyFuture{
+public class NonThreadedReplyFuture implements ReplyFuture {
// used to wait for done status
protected final Object donelock = new Object();
-
- //List of responses (i.e. message results)
+
+ // List of responses (i.e. message results)
protected final List<String> responses = new ArrayList<String>();
-
- // List of responders, used to build initial list of previous responders for multicast convergence
+
+ // List of responders, used to build initial list of previous responders for
+ // multicast convergence
protected final List<String> responders = new ArrayList<String>();
-
+
// point when reply future is closed automatically
protected long timeout;
-
+
// set to true when all operations producing results have completed
protected boolean done = false;
-
+
// the next position to be returned using the next() method.
// currently a future object is read by only one consumer.
private int nextPosition = 0;
-
- // the list of scopes this future has to cover, used to control correct closure.
+
+ // the list of scopes this future has to cover, used to control correct
+ // closure.
private List<String> unhandledScopes = new ArrayList<String>();
-
-
-
+
/**
- * Basic constructor, sets a default timeout value and uses all scopes definied in CONFIG
+ * Basic constructor, sets a default timeout value and uses all scopes
+ * definied in CONFIG
*/
- public NonThreadedReplyFuture(){
- //TODO: which wait time should we use here? has to be larger than the time it takes to start and end the multicast convergence
- this(SLPCore.CONFIG.getWaitTime()*5);
- }
-
-
-
-
+ public NonThreadedReplyFuture() {
+ // TODO: which wait time should we use here? has to be larger than the
+ // time it takes to start and end the multicast convergence
+ this(SLPCore.CONFIG.getWaitTime() * 5);
+ }
+
/**
- * Constructor with a specific lifetime. The future expects to handle all scopes defined in CONFIG
+ * Constructor with a specific lifetime. The future expects to handle all
+ * scopes defined in CONFIG
*
* @param lifetime
- * Number of milliseconds this future should remain open to receive results.
+ * Number of milliseconds this future should remain open to
+ * receive results.
*/
- public NonThreadedReplyFuture(long lifetime){
- unhandledScopes = SLPUtils.stringToList(SLPCore.CONFIG.getScopes().toLowerCase(), ",");
- timeout = System.currentTimeMillis()+lifetime;
-
+ public NonThreadedReplyFuture(final long lifetime) {
+ unhandledScopes = SLPUtils.stringToList(SLPCore.CONFIG.getScopes()
+ .toLowerCase(), ",");
+ timeout = System.currentTimeMillis() + lifetime;
+
}
-
-
+
/**
* Detailed constructor.
*
* @param lifetime
- * Number of milliseconds this future should remain open to receive results.
+ * Number of milliseconds this future should remain open to
+ * receive results.
* @param scopes
- * List of scopes to be handled.
+ * List of scopes to be handled.
*/
- public NonThreadedReplyFuture(long lifetime,List<String> scopes){
- for (String s : scopes){
+ public NonThreadedReplyFuture(final long lifetime, final List<String> scopes) {
+ for (final String s : scopes) {
unhandledScopes.add(s.toLowerCase());
}
- timeout = System.currentTimeMillis()+lifetime;
-
+ timeout = System.currentTimeMillis() + lifetime;
+
}
-
-
-
+
/**
- * Adds the result of an SLP reply message to the list of responses and the sender of the
- * reply to the list of responders, if the error code is 0.
+ * Adds the result of an SLP reply message to the list of responses and the
+ * sender of the reply to the list of responders, if the error code is 0.
*
* @param reply
- * An AbstractSLPReplyMessage obtained through unicast or multicast
+ * An AbstractSLPReplyMessage obtained through unicast or
+ * multicast
*/
- public void add(AbstractSLPReplyMessage reply){
+ public void add(final AbstractSLPReplyMessage reply) {
- if (System.currentTimeMillis()>=timeout){
- setDone(new String[]{}, true);
+ if (System.currentTimeMillis() >= timeout) {
+ setDone(new String[] {}, true);
return;
}
-
- if (reply==null || reply.getErrorCode()!=0){
+
+ if (reply == null || reply.getErrorCode() != 0) {
return;
}
- if (done){
+ if (done) {
// this reply is coming in too late...
return;
}
-
- synchronized (responders){
+
+ synchronized (responders) {
if (!responders.contains(reply.getSource())) {
responders.add(reply.getSource());
} else {
return;
}
}
-
- synchronized(responses){
- List<String> res = reply.getResultAsList();
- if (res!=null && res.size()>0){
- List<String> resp = reply.getResultAsList();
- for (String s: resp){
- if (!responses.contains(s)){
+
+ synchronized (responses) {
+ final List<String> res = reply.getResultAsList();
+ if (res != null && res.size() > 0) {
+ final List<String> resp = reply.getResultAsList();
+ for (final String s : resp) {
+ if (!responses.contains(s)) {
responses.add(s);
}
}
responses.notifyAll();
}
}
-
+
}
-
+
/**
- * Close the future.
- * If the override flag is set, the future will be closed directly.
- * If override is false, then the defined scopes will be removed from the list of unhandled scopes
- * and the future will be closed only if no scopes remain unhandled. Else it will remain open.
+ * Close the future. If the override flag is set, the future will be closed
+ * directly. If override is false, then the defined scopes will be removed
+ * from the list of unhandled scopes and the future will be closed only if
+ * no scopes remain unhandled. Else it will remain open.
*
* @param scopes
- * The scopes to mark as done.
+ * The scopes to mark as done.
* @param override
- * Set to true if the future should be closed even if scopes remain unhandled (e.g. timeout)
+ * Set to true if the future should be closed even if scopes
+ * remain unhandled (e.g. timeout)
*/
- public synchronized void setDone(String[] scopes, boolean override){
- synchronized (unhandledScopes){
- for (String s: scopes){
+ public synchronized void setDone(final String[] scopes,
+ final boolean override) {
+ synchronized (unhandledScopes) {
+ for (final String s : scopes) {
unhandledScopes.remove(s);
}
}
-
- if (!unhandledScopes.isEmpty() && !override){
- //oops, not all scopes that were expected to be handled actually were handled, so keep waiting
+
+ if (!unhandledScopes.isEmpty() && !override) {
+ // oops, not all scopes that were expected to be handled actually
+ // were handled, so keep waiting
return;
}
- if (!done){
- done=true;
- synchronized(donelock){
+ if (!done) {
+ done = true;
+ synchronized (donelock) {
donelock.notifyAll();
}
- synchronized(responses){
+ synchronized (responses) {
responses.notifyAll();
}
-
+
}
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.ServiceLocationEnumeration#next()
*/
- public String next(){
- // NOTE: a future is currently only read by one consumer (i.e. LocatorImpl) and therefor a single
- // position marker is sufficient. Also the data containers holding responses must add new elements to the end.
- synchronized(responses){
- while (!done){
- long remaining = timeout - System.currentTimeMillis();
- if (remaining>0){
- if (responses.size()>nextPosition){
+ public String next() {
+ // NOTE: a future is currently only read by one consumer (i.e.
+ // LocatorImpl) and therefor a single
+ // position marker is sufficient. Also the data containers holding
+ // responses must add new elements to the end.
+ synchronized (responses) {
+ while (!done) {
+ final long remaining = timeout - System.currentTimeMillis();
+ if (remaining > 0) {
+ if (responses.size() > nextPosition) {
return responses.get(nextPosition++);
}
- try{
+ try {
responses.wait(remaining);
- } catch (InterruptedException e){
+ } catch (final InterruptedException e) {
continue;
}
} else {
- setDone(new String[]{}, true);
+ setDone(new String[] {}, true);
break;
}
}
- if (responses.size()>nextPosition){
+ if (responses.size() > nextPosition) {
return responses.get(nextPosition++);
}
return null;
}
}
-
-
+
/**
* Returns the status of the future.
*
- * @return
- * True if done, false if results can still be added.
+ * @return True if done, false if results can still be added.
*/
- public synchronized boolean isDone(){
+ public synchronized boolean isDone() {
return done;
}
-
-
+
/**
- * Blocking call that waits until the future is marked as "done" before returning all available responses.
+ * Blocking call that waits until the future is marked as "done" before
+ * returning all available responses.
*
- * @return
- * A list of all results obtained during the unicast or multicast SLP operation in the form of Strings.
+ * @return A list of all results obtained during the unicast or multicast
+ * SLP operation in the form of Strings.
*/
- public List<String> getResult(){
- while (!done){
- synchronized (donelock){
+ public List<String> getResult() {
+ while (!done) {
+ synchronized (donelock) {
try {
- long remaining = timeout - System.currentTimeMillis();
- if (remaining>0){
+ final long remaining = timeout - System.currentTimeMillis();
+ if (remaining > 0) {
donelock.wait(remaining);
} else {
- setDone(new String[]{}, true);
+ setDone(new String[] {}, true);
break;
}
- } catch (InterruptedException ie){
+ } catch (final InterruptedException ie) {
continue;
}
}
}
return responses;
}
-
-
+
/**
- * Returns the sources of all reply messages with error code 0 passed on to this future.
+ * Returns the sources of all reply messages with error code 0 passed on to
+ * this future.
*
- * @return
- * Array of IP addresses as Strings in dot notation of the sources of reply messages.
+ * @return Array of IP addresses as Strings in dot notation of the sources
+ * of reply messages.
*/
- public synchronized String[] getResponders(){
+ public synchronized String[] getResponders() {
return SLPUtils.listToStringArray(responders);
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see java.util.Enumeration#hasMoreElements()
*/
public synchronized boolean hasMoreElements() {
- return (responses.size()>nextPosition);
+ return responses.size() > nextPosition;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.util.Enumeration#nextElement()
*/
public String nextElement() {
return next();
}
-
-
-
-
-
-
-
-
-
-
-
-
+
}
Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/OSGiPlatformAbstraction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/OSGiPlatformAbstraction.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/OSGiPlatformAbstraction.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/OSGiPlatformAbstraction.java Tue Jun 9 12:50:45 2009
@@ -46,7 +46,7 @@
/**
*
*/
- private LogService log = new NullPatternLogService();
+ private LogService log = new NullPatternLogService();
/**
* Constructor.
@@ -57,21 +57,23 @@
* the LogService, or null.
* @param debug
* true if debugging is enabled.
- * @throws InvalidSyntaxException
- * may never happen
+ * @throws InvalidSyntaxException
+ * may never happen
*/
- OSGiPlatformAbstraction(BundleContext context) throws InvalidSyntaxException {
+ OSGiPlatformAbstraction(final BundleContext context)
+ throws InvalidSyntaxException {
this.context = context;
// initially get the LogService
final ServiceReference sref = context
.getServiceReference(LogService.class.getName());
if (sref != null) {
- this.log = (LogService) context.getService(sref);
+ log = (LogService) context.getService(sref);
}
// track the LogService for life cycle events
- context.addServiceListener(this, "(" + Constants.OBJECTCLASS + "=" + LogService.class.getName() + ")");
+ context.addServiceListener(this, "(" + Constants.OBJECTCLASS + "="
+ + LogService.class.getName() + ")");
logDebug("jSLP OSGi started.");
}
@@ -80,20 +82,21 @@
*
* @see org.apache.directory.slp.impl.PlatformAbstraction#createFilter(java.lang.String)
*/
- public Filter createFilter(String filterString) {
+ public Filter createFilter(final String filterString) {
try {
final org.osgi.framework.Filter filter = context
.createFilter(filterString);
return new Filter() {
- public boolean match(Dictionary values) {
+ public boolean match(final Dictionary values) {
return filter.match(values);
}
+ @Override
public String toString() {
return filter.toString();
}
};
- } catch (InvalidSyntaxException e) {
+ } catch (final InvalidSyntaxException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
@@ -102,8 +105,8 @@
*
* @see org.apache.directory.slp.impl.PlatformAbstraction#logDebug(java.lang.String)
*/
- public void logDebug(String message) {
- if(SLPCore.CONFIG.getDebugEnabled()) {
+ public void logDebug(final String message) {
+ if (SLPCore.CONFIG.getDebugEnabled()) {
log.log(LogService.LOG_DEBUG, message);
}
}
@@ -113,8 +116,8 @@
* @see org.apache.directory.slp.impl.PlatformAbstraction#logDebug(java.lang.String,
* java.lang.Throwable)
*/
- public void logDebug(String message, Throwable exception) {
- if(SLPCore.CONFIG.getDebugEnabled()) {
+ public void logDebug(final String message, final Throwable exception) {
+ if (SLPCore.CONFIG.getDebugEnabled()) {
log.log(LogService.LOG_DEBUG, message, exception);
}
}
@@ -123,7 +126,7 @@
*
* @see org.apache.directory.slp.impl.PlatformAbstraction#logError(java.lang.String)
*/
- public void logError(String message) {
+ public void logError(final String message) {
log.log(LogService.LOG_ERROR, message);
}
@@ -132,7 +135,7 @@
* @see org.apache.directory.slp.impl.PlatformAbstraction#logError(java.lang.String,
* java.lang.Throwable)
*/
- public void logError(String message, Throwable exception) {
+ public void logError(final String message, final Throwable exception) {
log.log(LogService.LOG_ERROR, message, exception);
}
@@ -140,8 +143,8 @@
*
* @see org.apache.directory.slp.impl.PlatformAbstraction#logTraceMessage(java.lang.String)
*/
- public void logTraceMessage(String message) {
- if(SLPCore.CONFIG.getTraceMessage()) {
+ public void logTraceMessage(final String message) {
+ if (SLPCore.CONFIG.getTraceMessage()) {
log.log(LogService.LOG_INFO, message);
}
}
@@ -150,8 +153,8 @@
*
* @see org.apache.directory.slp.impl.PlatformAbstraction#logTraceDrop(java.lang.String)
*/
- public void logTraceDrop(String message) {
- if(SLPCore.CONFIG.getTraceDrop()) {
+ public void logTraceDrop(final String message) {
+ if (SLPCore.CONFIG.getTraceDrop()) {
log.log(LogService.LOG_INFO, message);
}
}
@@ -160,8 +163,8 @@
*
* @see org.apache.directory.slp.impl.PlatformAbstraction#logTraceMessage(java.lang.String)
*/
- public void logTraceReg(String message) {
- if(SLPCore.CONFIG.getTraceReg()) {
+ public void logTraceReg(final String message) {
+ if (SLPCore.CONFIG.getTraceReg()) {
log.log(LogService.LOG_INFO, message);
}
}
@@ -170,7 +173,7 @@
*
* @see org.apache.directory.slp.impl.PlatformAbstraction#logWarning(java.lang.String)
*/
- public void logWarning(String message) {
+ public void logWarning(final String message) {
log.log(LogService.LOG_WARNING, message);
}
@@ -179,7 +182,7 @@
* @see org.apache.directory.slp.impl.PlatformAbstraction#logWarning(java.lang.String,
* java.lang.Throwable)
*/
- public void logWarning(String message, Throwable exception) {
+ public void logWarning(final String message, final Throwable exception) {
log.log(LogService.LOG_WARNING, message, exception);
}
@@ -197,27 +200,31 @@
default:
}
}
-
+
// if no LogService is present, we use a dummy log
private class NullPatternLogService implements LogService {
- public void log(int level, String message) {
- if(level == LogService.LOG_ERROR || level == LogService.LOG_WARNING) {
+ public void log(final int level, final String message) {
+ if (level == LogService.LOG_ERROR
+ || level == LogService.LOG_WARNING) {
System.err.println(message);
} else {
System.out.println(message);
}
}
- public void log(int level, String message, Throwable exception) {
+ public void log(final int level, final String message,
+ final Throwable exception) {
log(level, message + exception.getMessage());
}
- public void log(ServiceReference sr, int level, String message) {
+ public void log(final ServiceReference sr, final int level,
+ final String message) {
log(null, level, message);
}
- public void log(ServiceReference sr, int level, String message, Throwable t) {
+ public void log(final ServiceReference sr, final int level,
+ final String message, final Throwable t) {
log(null, level, message, t);
}
}
Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPAttributeImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPAttributeImpl.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPAttributeImpl.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPAttributeImpl.java Tue Jun 9 12:50:45 2009
@@ -26,7 +26,6 @@
import org.apache.directory.slp.SLPAttribute;
import org.apache.directory.slp.ServiceLocationException;
-
/**
*
* @author Lorenz Breu
@@ -35,340 +34,384 @@
private List values;
private String name = "";
- private int type;
- private String typeString = "";
-
-
+ private final int type;
+ private final String typeString = "";
+
/**
- * Creates a new SLPAttributeImpl with the given name and values: "(name=values)"
+ * Creates a new SLPAttributeImpl with the given name and values:
+ * "(name=values)"
*
* @param name
- * The attibute name
+ * The attibute name
* @param a_values
- * The value(s) of the attribute. Types are checked on creation
+ * The value(s) of the attribute. Types are checked on creation
* @throws ServiceLocationException
- * If the types of values are not consistent
+ * If the types of values are not consistent
*/
- public SLPAttributeImpl(String name,List<String> a_values) throws ServiceLocationException{
- this.name=name;
+ public SLPAttributeImpl(final String name, final List<String> a_values)
+ throws ServiceLocationException {
+ this.name = name;
type = checkAndSetType(a_values);
-
+
}
-
+
/**
- * Creates a new SLPAttributeImpl with the given name and values: "(name=values)"
+ * Creates a new SLPAttributeImpl with the given name and values:
+ * "(name=values)"
*
* @param name
- * The attibute name
+ * The attibute name
* @param a_values
- * The value(s) of the attribute. Types are checked on creation
+ * The value(s) of the attribute. Types are checked on creation
* @throws ServiceLocationException
- * If the types of values are not consistent
+ * If the types of values are not consistent
*/
- public SLPAttributeImpl(String name,String[] a_values) throws ServiceLocationException{
- this.name=name;
+ public SLPAttributeImpl(final String name, final String[] a_values)
+ throws ServiceLocationException {
+ this.name = name;
type = checkAndSetType(a_values);
-
+
}
-
-
+
/**
* Creates a new SLPAttributeImpl as a KEYWORD
*
* @param name
- * The attribute/keyword name
+ * The attribute/keyword name
*/
- public SLPAttributeImpl(String name){
- this.name=name;
- type=KEYWORD_AT;
- }
-
-
- /* (non-Javadoc)
+ public SLPAttributeImpl(final String name) {
+ this.name = name;
+ type = KEYWORD_AT;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.SLPAttribute#count()
*/
public int count() {
return values.size();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.SLPAttribute#getBooleanValues()
*/
public Boolean[] getBooleanValues() {
- if (type==BOOLEAN_AT){
+ if (type == BOOLEAN_AT) {
return (Boolean[]) values.toArray(new Boolean[values.size()]);
}
return null;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.SLPAttribute#getIntegerValues()
*/
public Integer[] getIntegerValues() {
- if (type==INTEGER_AT){
+ if (type == INTEGER_AT) {
return (Integer[]) values.toArray(new Integer[values.size()]);
}
return null;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.SLPAttribute#getName()
*/
public String getName() {
return name;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.SLPAttribute#getOpaqueValues()
*/
public OpaqueValue[] getOpaqueValues() {
- if (type==OPAQUE_AT){
- return (OpaqueValue[]) values.toArray(new OpaqueValue[values.size()]);
+ if (type == OPAQUE_AT) {
+ return (OpaqueValue[]) values
+ .toArray(new OpaqueValue[values.size()]);
}
return null;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.SLPAttribute#getStringValues()
*/
public String[] getStringValues() {
- String[] res = new String[values.size()];
- for (int i=0; i<res.length;i++){
+ final String[] res = new String[values.size()];
+ for (int i = 0; i < res.length; i++) {
res[i] = values.get(i).toString();
}
return res;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.SLPAttribute#getType()
*/
public int getType() {
return type;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.SLPAttribute#getTypeString()
*/
public String getTypeString() {
return typeString;
}
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see ch.ethz.iks.slp.SLPAttribute#isKeyword()
*/
public boolean isKeyword() {
- if (type==KEYWORD_AT){
+ if (type == KEYWORD_AT) {
return true;
}
return false;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#toString()
*/
- public String toString(){
- if (isKeyword()){
+ @Override
+ public String toString() {
+ if (isKeyword()) {
return name;
}
- String res = "("+name+"=";
- for (Object o:values){
- res+=o.toString()+", ";
+ String res = "(" + name + "=";
+ for (final Object o : values) {
+ res += o.toString() + ", ";
}
- res=res.substring(0,res.length()-2)+")";
+ res = res.substring(0, res.length() - 2) + ")";
return res;
}
-
+
/**
- * merges the values of another SLPAttribute with the same name and type into the ones of this one.
- * Silently discards attributes with different names and/or types
+ * merges the values of another SLPAttribute with the same name and type
+ * into the ones of this one. Silently discards attributes with different
+ * names and/or types
*
* @param other
- * The other SLPAttribute to be merged into this one
- *
+ * The other SLPAttribute to be merged into this one
+ *
*/
- public void merge(SLPAttribute other){
- if (!other.getName().equals(name) || other.getType()!=type){
+ public void merge(final SLPAttribute other) {
+ if (!other.getName().equals(name) || other.getType() != type) {
return;
}
- switch(type){
+ switch (type) {
case STRING_AT:
- String[] ovs = other.getStringValues();
- for (int i=0;i<ovs.length;i++){
- if (!values.contains(ovs[i])){
+ final String[] ovs = other.getStringValues();
+ for (int i = 0; i < ovs.length; i++) {
+ if (!values.contains(ovs[i])) {
values.add(ovs[i]);
}
}
break;
case INTEGER_AT:
- Integer[] ovi = other.getIntegerValues();
- for (int i=0;i<ovi.length;i++){
- if (!values.contains(ovi[i])){
+ final Integer[] ovi = other.getIntegerValues();
+ for (int i = 0; i < ovi.length; i++) {
+ if (!values.contains(ovi[i])) {
values.add(ovi[i]);
}
}
break;
case BOOLEAN_AT:
- Boolean[] ovb = other.getBooleanValues();
- for (int i=0;i<ovb.length;i++){
- if (!values.contains(ovb[i])){
+ final Boolean[] ovb = other.getBooleanValues();
+ for (int i = 0; i < ovb.length; i++) {
+ if (!values.contains(ovb[i])) {
values.add(ovb[i]);
}
}
break;
case OPAQUE_AT:
- OpaqueValue[] ovo = other.getOpaqueValues();
- for (int i=0;i<ovo.length;i++){
- if (!values.contains(ovo[i])){
+ final OpaqueValue[] ovo = other.getOpaqueValues();
+ for (int i = 0; i < ovo.length; i++) {
+ if (!values.contains(ovo[i])) {
values.add(ovo[i]);
}
}
break;
}
-
+
}
-
/**
- * Ensures the types on a List of Strings are consistent according to SLP RFC2608.
- * The values are set if no errors are encountered.
+ * Ensures the types on a List of Strings are consistent according to SLP
+ * RFC2608. The values are set if no errors are encountered.
*
* @param a_values
- * The values to be checked
- * @return
- * The type of the values
+ * The values to be checked
+ * @return The type of the values
* @throws ServiceLocationException
- * INTERNAL_SYSTEM_ERROR if inconsistent types are discovered
+ * INTERNAL_SYSTEM_ERROR if inconsistent types are discovered
*/
- private int checkAndSetType(List<String> a_values) throws ServiceLocationException{
+ private int checkAndSetType(final List<String> a_values)
+ throws ServiceLocationException {
int t = -1;
List v;
- if (a_values.size()<1){
- throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR,"no values given for this attribute "+name);
+ if (a_values.size() < 1) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR,
+ "no values given for this attribute " + name);
}
String init = a_values.get(0).trim();
- if (init.startsWith("\\FF")){
- t=OPAQUE_AT;
- v=new ArrayList<OpaqueValue>();
+ if (init.startsWith("\\FF")) {
+ t = OPAQUE_AT;
+ v = new ArrayList<OpaqueValue>();
v.add(new OpaqueValue(init));
- } else if (init.toLowerCase().equals("true") || init.toLowerCase().equals("false")){
- t=BOOLEAN_AT;
- v=new ArrayList<Boolean>();
+ } else if (init.toLowerCase().equals("true")
+ || init.toLowerCase().equals("false")) {
+ t = BOOLEAN_AT;
+ v = new ArrayList<Boolean>();
v.add(Boolean.valueOf(init));
} else {
try {
- int vi = Integer.parseInt(init);
- t=INTEGER_AT;
- v=new ArrayList<Integer>();
+ final int vi = Integer.parseInt(init);
+ t = INTEGER_AT;
+ v = new ArrayList<Integer>();
v.add(vi);
- } catch (NumberFormatException nfe){
- t=STRING_AT;
- v=new ArrayList<String>();
+ } catch (final NumberFormatException nfe) {
+ t = STRING_AT;
+ v = new ArrayList<String>();
v.add(init);
}
}
-
- for (int i=1;i<a_values.size();i++){
- init=a_values.get(i).trim();
- if (init.startsWith("\\FF")){
- if (t!=OPAQUE_AT){
- throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR,"inconsistent types for this attribute "+name);
+
+ for (int i = 1; i < a_values.size(); i++) {
+ init = a_values.get(i).trim();
+ if (init.startsWith("\\FF")) {
+ if (t != OPAQUE_AT) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR,
+ "inconsistent types for this attribute " + name);
}
v.add(new OpaqueValue(init));
-
- } else if (init.toLowerCase().equals("true") || init.toLowerCase().equals("false")){
- if (t!=BOOLEAN_AT){
- throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR,"inconsistent types for this attribute "+name);
+
+ } else if (init.toLowerCase().equals("true")
+ || init.toLowerCase().equals("false")) {
+ if (t != BOOLEAN_AT) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR,
+ "inconsistent types for this attribute " + name);
}
v.add(Boolean.valueOf(init));
} else {
try {
- int vi = Integer.parseInt(init);
- if (t!=INTEGER_AT){
- throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR,"inconsistent types for this attribute "+name);
+ final int vi = Integer.parseInt(init);
+ if (t != INTEGER_AT) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR,
+ "inconsistent types for this attribute " + name);
}
v.add(vi);
- } catch (NumberFormatException nfe){
- if (t!=STRING_AT){
- throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR,"inconsistent types for this attribute "+name);
+ } catch (final NumberFormatException nfe) {
+ if (t != STRING_AT) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR,
+ "inconsistent types for this attribute " + name);
}
v.add(init);
}
}
-
+
}
- values=v;
+ values = v;
return t;
-
+
}
-
+
/**
- * Ensures the types on a List of Strings are consistent according to SLP RFC2608.
- * The values are set if no errors are encountered.
+ * Ensures the types on a List of Strings are consistent according to SLP
+ * RFC2608. The values are set if no errors are encountered.
*
* @param a_values
- * The values to be checked
- * @return
- * The type of the values
+ * The values to be checked
+ * @return The type of the values
* @throws ServiceLocationException
- * INTERNAL_SYSTEM_ERROR if inconsistent types are discovered
+ * INTERNAL_SYSTEM_ERROR if inconsistent types are discovered
*/
- private int checkAndSetType(String[] a_values) throws ServiceLocationException{
+ private int checkAndSetType(final String[] a_values)
+ throws ServiceLocationException {
int t = -1;
List v;
String init = a_values[0].trim();
- if (init.startsWith("\\FF")){
- t=OPAQUE_AT;
- v=new ArrayList<OpaqueValue>();
+ if (init.startsWith("\\FF")) {
+ t = OPAQUE_AT;
+ v = new ArrayList<OpaqueValue>();
v.add(new OpaqueValue(init));
- } else if (init.toLowerCase().equals("true") || init.toLowerCase().equals("false")){
- t=BOOLEAN_AT;
- v=new ArrayList<Boolean>();
+ } else if (init.toLowerCase().equals("true")
+ || init.toLowerCase().equals("false")) {
+ t = BOOLEAN_AT;
+ v = new ArrayList<Boolean>();
v.add(Boolean.valueOf(init));
} else {
try {
- int vi = Integer.parseInt(init);
- t=INTEGER_AT;
- v=new ArrayList<Integer>();
+ final int vi = Integer.parseInt(init);
+ t = INTEGER_AT;
+ v = new ArrayList<Integer>();
v.add(vi);
- } catch (NumberFormatException nfe){
- t=STRING_AT;
- v=new ArrayList<String>();
+ } catch (final NumberFormatException nfe) {
+ t = STRING_AT;
+ v = new ArrayList<String>();
v.add(init);
}
}
-
- for (int i=1;i<a_values.length;i++){
- init=a_values[i];
- if (init.startsWith("\\FF")){
- if (t!=OPAQUE_AT){
- throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR,"inconsistent types for this attribute "+name);
+
+ for (int i = 1; i < a_values.length; i++) {
+ init = a_values[i];
+ if (init.startsWith("\\FF")) {
+ if (t != OPAQUE_AT) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR,
+ "inconsistent types for this attribute " + name);
}
v.add(new OpaqueValue(init));
-
- } else if (init.toLowerCase().equals("true") || init.toLowerCase().equals("false")){
- if (t!=BOOLEAN_AT){
- throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR,"inconsistent types for this attribute "+name);
+
+ } else if (init.toLowerCase().equals("true")
+ || init.toLowerCase().equals("false")) {
+ if (t != BOOLEAN_AT) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR,
+ "inconsistent types for this attribute " + name);
}
v.add(Boolean.valueOf(init));
} else {
try {
- int vi = Integer.parseInt(init);
- if (t!=INTEGER_AT){
- throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR,"inconsistent types for this attribute "+name);
+ final int vi = Integer.parseInt(init);
+ if (t != INTEGER_AT) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR,
+ "inconsistent types for this attribute " + name);
}
v.add(vi);
- } catch (NumberFormatException nfe){
- if (t!=STRING_AT){
- throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR,"inconsistent types for this attribute "+name);
+ } catch (final NumberFormatException nfe) {
+ if (t != STRING_AT) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR,
+ "inconsistent types for this attribute " + name);
}
v.add(init);
}
}
-
+
}
-
+
return t;
-
+
}
}
Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPConfiguration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPConfiguration.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPConfiguration.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPConfiguration.java Tue Jun 9 12:50:45 2009
@@ -33,7 +33,6 @@
import java.util.Properties;
import java.util.StringTokenizer;
-
/**
* SLPConfiguration object holds all configurable properties.
*
@@ -226,18 +225,19 @@
* in case of IO errors.
*/
SLPConfiguration(final File file) throws IOException {
- Properties props = new Properties();
+ final Properties props = new Properties();
props.load(new FileInputStream(file));
props.putAll(System.getProperties());
processProperties(props);
}
private static void processProperties(final Properties props) {
- String ifaces = props.getProperty(INTERFACES_PROP, INTERFACES_DEFAULT);
+ final String ifaces = props.getProperty(INTERFACES_PROP,
+ INTERFACES_DEFAULT);
if (ifaces == null) {
INTERFACES = null;
} else {
- INTERFACES = (String[]) SLPUtils.stringToStringArray(ifaces, ",");
+ INTERFACES = SLPUtils.stringToStringArray(ifaces, ",");
}
PORT = Integer.parseInt(props.getProperty(PORT_PROP, DEFAULT_PORT));
SCOPES = props.getProperty(USE_SCOPES_PROP, USE_SCOPES_DEFAULT);
@@ -435,8 +435,8 @@
* @return the timeout int array.
*/
private static int[] parseTimeouts(final String s) {
- StringTokenizer st = new StringTokenizer(s, ",");
- int[] timeouts = new int[st.countTokens()];
+ final StringTokenizer st = new StringTokenizer(s, ",");
+ final int[] timeouts = new int[st.countTokens()];
for (int i = 0; i < timeouts.length; i++) {
timeouts[i] = Integer.parseInt(st.nextToken());
}
@@ -499,17 +499,17 @@
*/
public PublicKey getPublicKey(final String spi) throws IOException,
GeneralSecurityException {
- PublicKey key = (PublicKey) PUBLIC_KEY_CACHE.get(spi);
+ PublicKey key = PUBLIC_KEY_CACHE.get(spi);
if (key != null) {
return key;
}
- FileInputStream keyfis = new FileInputStream(System
+ final FileInputStream keyfis = new FileInputStream(System
.getProperty(PUBLIC_KEY_PROP + spi));
- byte[] encKey = new byte[keyfis.available()];
+ final byte[] encKey = new byte[keyfis.available()];
keyfis.read(encKey);
keyfis.close();
- X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey);
- KeyFactory keyFactory = KeyFactory.getInstance("DSA");
+ final X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey);
+ final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
key = keyFactory.generatePublic(pubKeySpec);
PUBLIC_KEY_CACHE.put(spi, key);
return key;
@@ -526,20 +526,20 @@
*/
public PrivateKey getPrivateKey(final String spi) throws IOException,
GeneralSecurityException {
- PrivateKey key = (PrivateKey) PRIVATE_KEY_CACHE.get(spi);
+ PrivateKey key = PRIVATE_KEY_CACHE.get(spi);
if (key != null) {
return key;
}
- FileInputStream keyfis = new FileInputStream(System
+ final FileInputStream keyfis = new FileInputStream(System
.getProperty(PRIVATE_KEY_PROP + spi));
- byte[] encKey = new byte[keyfis.available()];
+ final byte[] encKey = new byte[keyfis.available()];
keyfis.read(encKey);
keyfis.close();
- PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(encKey);
+ final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(encKey);
- KeyFactory keyFactory = KeyFactory.getInstance("DSA");
+ final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
key = keyFactory.generatePrivate(privKeySpec);
PRIVATE_KEY_CACHE.put(spi, key);
return key;